Tagged Questions
0
votes
1answer
22 views
Java compareAndSet to atomically update references in a BST
In a binary tree, I'm trying to atomically replace left child of parent to a new node.
In the below method, pnode.left is pointing to node and I'm trying to change it
to replaceNode.
In line1, ...
1
vote
6answers
54 views
Java threading and outputstream printinng issue
Hi I am just trying my hands with threading, Just a Request its not a homework or anything its just testing of my understanding of the subject, so those who doesnt like it please dont close it there ...
1
vote
0answers
41 views
Resettable timer performance in Java
When profiling my app, I found a source of frequent allocations... I have multiple timers that that check for timeouts (~2ms, varies with app state).
According to this SO answer, ...
2
votes
2answers
45 views
List ConcurrentModificationException
I have the following code
public void saveProjects(List<Project> proj) throws DatabaseException {
for (Project listItems: proj) { // error here
insertProjects(listItems);
}
}
...
0
votes
1answer
48 views
multithreading to calculate primes java
I am trying to parallelize a prime number counter as an exercise.
I have refactored the original code and separated the long loops from others so that I can parallelize them.
Now I have the following ...
0
votes
0answers
29 views
Reader-writer visibility in Java LinkedBlockingQueue
I have confusion about JDK6+ LinkedBlockingQueue reader-writer visibility implementations.
Source codes in JDK 1.6.45:
static class Node<E> {
E item;
Node<E> next;
Node(E x) ...
0
votes
0answers
16 views
Java Monitors — Catching InterruptedException
I have a java implementation of a monitor using
java.util.concurrent.locks.Lock;
java.util.concurrent.locks.ReentrantLock;
java.util.concurrent.locks.Condition;
The problem that I'm solving is a ...
0
votes
2answers
65 views
How to concurrently modify a Vector
I have to ensure while iterating the Vector; there is no update on that Vector to avoid ConcurrentModificationException. I can use concurrent collection. But i just want to give a try on Vector. Below ...
4
votes
2answers
86 views
Why there is no AtomicBooleanArray datatype in Java?
I have noticed that there is NO AtomicBooleanArray datatype in Java similar to the AtomicIntegerArray. Although I can use AtomicBoolean[] for my current needs, I was curious to get an understanding ...
0
votes
4answers
81 views
If I simply need to guarantee `happens-before` relation, and not atomicity, should I use a concurrent class or a synchronized block?
I am developing a pool mechanism. Objects in the pool will be used by different threads. Thus I need to guarantee that there will be a happens-before relation when accessing non-final attributes of ...
5
votes
3answers
70 views
Concurrent request processing in Java with constraints
Suppose I need to process requests of 3 types: A, B, and C as follows:
Requests are processed concurrently.
There are at most K (<= 3) requests to be processed concurrently at the same time.
...
0
votes
3answers
55 views
When will call the executor.shutdown () method [closed]
If there’s N number of requests comes from DB based on queued state, but we have only 10 threads are maintained the pool
My question is when will call the executor.shutdown () method, Is there any ...
0
votes
1answer
60 views
Multiple Threads spawning multiple threads and how to wait for child Threads
I have two arrays abc[100] and def[1000] and I have to find an array xyz[100] , where xyz[i] = minDistance(abc[i],def) i.e for every element in abc i have to find a corresponding nearest element in ...
-1
votes
0answers
46 views
JAX-WS: Concurrent calls from client
I want to make multiple simultaneous calls to a web service. I have implemented the Asynchronous Client using the CallBack approach. Any pointers how to implement multiple calls from the client at the ...
0
votes
1answer
88 views
Pause and Resume ExecutorService or shutdown and restart Java Executor service
I am working on a javaFX project where user simply browse few files, create a queue of it, click on start upload and upload started of these files on a specified path. Now when user click on ...
0
votes
1answer
85 views
Callbacks for scheduled future in java
Are there any ways to add callbacks(on success, on fail) to ScheduledFuture? Seems guava with ListneableFuture doesn't provide this.
0
votes
2answers
28 views
Restarting cancelled tasks in ScheduledThreadPoolExecutor
I am creating tasks with ScheduledThreadPoolExecutor and adding the Futures to a list as below in my ThreadFactory class.
private static List<Future> futures;
........
ScheduledFuture sf = ...
1
vote
2answers
69 views
Non-blocking method to start several threads and run a callabck on the parent thread when all children have finished
The main thing is that the callback should be on the PARENT thread and not called from the task, which is finishing the job (e.g. NOT like ThreadPoolExecutor's afterExecute() hook).
I'd like to have ...
0
votes
1answer
36 views
Is ReentrantLock Facade design pattern implementation?
I am learning design patterns, and after going through the text book examples, I am focusing on JDK implementation of design patterns.
ReentrantLock class in java.concurrent.Lock package use ...
1
vote
1answer
31 views
Origins of the TimeoutException
Are the:
Future#get (FutureTask#get)
ExecutorService.html#invokeAny
only methods that can throw a java.util.concurrent.TimeoutException?
0
votes
1answer
70 views
How to read data concurrently using java?
I have a method which takes a string as input and returns data from the DB based on the input string. I have an array of strings and I am currently passing each string as input and looping over the ...
0
votes
2answers
52 views
Java: Exception in thread “AWT-EventQueue-0” java.util.ConcurrentModificationException
i am currently trying to code my own little 2D Game. It's a Helicopter dodging rockets.
these rockets flighing from right to the left. If they are outside of the Panel they should be deleted.
this ...
1
vote
2answers
42 views
Reuse of a worker instance to handle several tasks
I have an application for web testing (based on Selenium but this should not matter much here) which executes quite a number of test cases successively. It takes a couple of hours to complete and the ...
2
votes
2answers
97 views
Will the use of volatile & atomic always ensures thread safety
I get mixed answer whenever I look for concurrent access , JCIP book I have already ordered and is on the way , but I want to nail this concurrency basics of mine , here is my scenario
I have 3 ...
0
votes
2answers
44 views
How to make sure elements of a concurrent list in java, that are added after the list has been looped through, are handled properly?
I have a concurrent list of objects. Multiple threads add to this list. At some point I loop through this list and perform operations on the list elements. How do I ensure that I process the elements ...
3
votes
2answers
62 views
Why Atomic versions are missing for some primitive types while being present for some?
Java provides AtomicInteger,AtomicLong etc which basically compiles to CAS instructions at hardware level. But why such AtomicXXX classes do not exist for other primitive types like short and ...
0
votes
1answer
79 views
Java Executor - not running threads in parallel
I am trying to execute independent task parallel using the java.util.concurrent.Executor.
I have the following working code
public class MiniTest {
private static String[] input;
...
1
vote
3answers
72 views
Need to manually synchronize the Synchronized list while iteration when it could be avoided?
My question is about synchronizedList method Collections Class.
Javadocs say:
It is imperative that the user manually synchronize on the returned list when iterating over it:
List list = ...
0
votes
2answers
42 views
Java semaphore + No synchronization lock is held when acquire() is called
I am not able to understand the meaning of below line which is provided on link JavaWorld
No synchronization lock is held when acquire() is called because that would prevent an item from being ...
1
vote
2answers
54 views
Interrupting a Runnable with a method of the class
How can I write a method of a class implementing the Runnable interface (started from an ExecutorService) that would interrupt the thread?
I know that I can use Future fut = es.submit(foo); (where es ...
1
vote
2answers
54 views
Iterating over ConcurrentSkipListSet with different thread removing elements
I have a ConcurrentSKipListSet, and I'm iterating over values in this set with a for-each loop.
Another thread at some point is going to remove an element from this set.
I think I'm running into a ...
3
votes
1answer
84 views
Why not use a pseudo random number generator to produce test data?
From the book Java Concurrency in Practice , Chapter 12.1 Testing for correctness, specifically in sub-section 12.1.3 Testing safety(where the author wants to set up test cases for testing data-race ...
0
votes
2answers
60 views
Ensure that a task is interruptible
How to ensure that my tasks are responsive to interruption when I call Future.cancel()?
ExecutorService executor = Executors.newSingleThreadExecutor();
Future<Boolean> future = ...
3
votes
3answers
74 views
Awaiting multiple instances of CountDownLatch in container
I wrote a class CountDownLatchContainer it has a await() method, that waits on all CountDownLatches. Everything is working fine.
public final class CountDownLatchContainer
{
private final ...
1
vote
0answers
47 views
Set a timeout in Executor.execute()
I need to execute tasks sequentially:
Executor executor = Executors.newSingleThreadExecutor();
public void push(Runnable task) {
executor.execute(task);
}
Sometimes a task never ends. I would ...
1
vote
2answers
87 views
Fire and forget with java.util.concurrent
How to go about implementing a "fire and forget" behavior with java.util.concurrency? I tried:
ExecutorService executor = Executors.newSingleThreadExecutor();
public void ...
1
vote
3answers
135 views
Print RED BLUE GREEN in order using System.out.print
public class CyclicBar {
private final static CyclicBarrier cb = new CyclicBarrier(3,
new Runnable() {
@Override
public void run() {
...
0
votes
1answer
66 views
Why is HashEntry in ConcurrentHashMap final?
I am going through source code of ConcurrentHashMap in jdk 7 and have few doubts.
I have already gone through all the questions on CHM on StackOverFlow, but could not find the answer.
Is get ...
1
vote
3answers
113 views
Java Events - java.util.ConcurrentModificationException
Yes I'm sure this question exist, but I have tried the answers and I guess I need a custom answer..
Anyway as the title suggest I'm getting a java.util.ConcurrentModificationException.
All this is ...
1
vote
2answers
69 views
Does a Synchronous Queue create a thread on each offer/put?
I can not understand how the Synchronous Queue works.
I understand that the idea is that the handover of tasks is to threads directly but the constructor does not have a bound e.g max number of ...
3
votes
5answers
160 views
What is the purpose of WeakHashMap when there is HashMap and Concurrent HashMap?
What is the need arises for introducing Weak HashMap when there is already other implementations available.
In short i have two issues :
Why jdk has WeakHashMap when there is HashMap and ...
3
votes
1answer
70 views
Trying to understand the mechanics of a synchronous queue
I was trying to read the implementation of Synchronous Queue
It is not so straightforward for me. It seems to be using a linked list where each node is associated with a thread.
And the core part uses ...
0
votes
0answers
129 views
Will this (generated) thrift client use the connection pool referenced in this code?
On this apache thrift wiki article, there is a good example of a generated thrift client utilizing a client connection pool through a referenced connection manager (cm in the code below), in a junit ...
0
votes
3answers
89 views
Do callable executes sequentially?
Whenever i run my program implementing callable, i get the output in a sequential form.
Like, here is my program :
package com.handson;
import java.util.concurrent.ArrayBlockingQueue;
import ...
1
vote
2answers
48 views
How does the Exchanger supports GC-less Java?
While reading about concurrent api of java, i came to know about Exchanger class.
From Java docs,
"A synchronization point at which threads can pair and swap elements within pairs. Each thread ...
0
votes
3answers
104 views
how to maximize resource (RAM and CPU) usage with multi-threaded java programming?
my code is running on a 32-bit JVM (JRE v1.6) on Windows 2008 Server (64-bit) with 128 GB of RAM and 64 cores. however, the maximum heap space i can ever specify is 1.5 GB. my code looks the ...
2
votes
1answer
80 views
How to make Weakrefernce in Concurrent HashMap
In my Program I have a scenario, where Mutiple Thread will operate (put and get) on a single Map. Like Thread a using put a key/value in the map and the same time another thread is retrieving the ...
0
votes
1answer
36 views
ConcurrentHash map with Weak Reference
I am stuck in a problem and really need some help to go through this
In my application. I have a ConcurrentHashMap where multiple can thread can store or retrieve data simultaneously. To solve this ...
1
vote
1answer
97 views
Is a ConcurrentHashSet required if threads are using different keys?
Suppose I have a hash set of request IDs that I've sent from a client to a server. The server's response returns the request ID that I sent, which I can then remove from the hash set. This will be ...
0
votes
2answers
57 views
Non volatile status flag in multi-threaded code
I am a novice when it comes to concurrency and unsure of myself when spotting issues, I was looking through a fairly established code base and found the following code (edited for brevity) which I ...