Java package which contains utility classes commonly useful in concurrent programming. This package includes a few small standardized extensible frameworks, as well as some classes that provide useful functionality and are otherwise tedious or difficult to implement.

learn more… | top users | synonyms

1
vote
0answers
32 views

How to achieve Thread Safety in Java between Multiple JVM or containers if they access shared memory?

We Know that Synchronized Keyword would work when there is only one JVM but if there more than 1 JVM , meaning there are more than 1 instance of JVM , So in that case how can we achieve thread safety ?...
-1
votes
1answer
36 views

ForkJoinPool BufferedImage Processing Style

I am trying to process an image using a ForkJoinPool in java. I used streams to do some custom operations on the image. I am trying to use ForkJoinPool for getRGB and setRGB methods. How do I achieve ...
-1
votes
0answers
31 views

Parsing Multiple Files and Their Contents in Java using Multithreading without ExecutorService [on hold]

I'm learning concurrency in Java and went over the tutorials on oracle website. While I have understood some of it, a greater portion eludes me. I was thinking of a hypothetical problem (though it may ...
0
votes
3answers
32 views

Adding to AtomicInteger within ConcurrentHashMap

I have the following defined private ConcurrentMap<Integer, AtomicInteger> = new ConcurrentHashMap<Integer, AtomicInteger>(); private void add() { staffValues.replace(100, staffValues....
0
votes
1answer
31 views

java.util.ConcurrentModificationException in Android Game Loop

I am using a canvas, moving objects on the screen, when an object hit the left side of the canvas (x=0), another object of the same type gets instantiated, and start moving on the screen. Everything ...
0
votes
1answer
48 views

Why do I get inconsistencies in this method when running

Sometimes the varible total will equal something else when run instead of 50005000 it's allways short like 50005001 when sometimes run why is this happening shouldn't synchronized(this) create a lock ...
0
votes
2answers
37 views

Concurrency (ReentrantLock) in diffrent threads

I need to use ReentrantLock in diffrent threads. Does it possible? P.S. In secondMethod "lock.unlock()" throw IllegalMonitorStateException. public class SomeClass { private static ...
2
votes
1answer
84 views

No worker threads when fork-join has work to do?

I've got a bug that's come up twice in production now where one of my fork/join pools stops working, even though it has work to do and more work is being added. This is the conclusion I've come to so ...
3
votes
0answers
22 views

CopyOnWriteArrayList: understanding small detail [duplicate]

CopyOnWriteArrayList methods that mutate its state (add, set, etc) acquire the lock following way: final ReentrantLock lock = this.lock; lock.lock(); Why does it save this.lock into a local variable?...
1
vote
1answer
53 views

Why lamda inside map is not running?

I am trying to learn concurrency and lamdas in java 8. But my code is not entering lamda block inside map. List<Book> bookList = new ArrayList<Book>(); isbnList .stream() ....
0
votes
2answers
57 views

Is synchronized locking a Reentrantlock, or only its object?

The normal pattern with ReentrantLock and lock()/unlock() is like this: lck.lock(); try { // ... } finally { lck.unlock(); } Can this be refactored to synchronized(lck) { // ... } ? ...
2
votes
1answer
43 views

Shutdown now on ExecutionException

I read a lot of post about ExecutorService, but I can't find the way of doing what I need. I need some concurrent threads. When any of them throw a custom exception all the remaining tasks are ...
2
votes
1answer
35 views

Thread race condition just hangs while using PipedOutputStream

I am using piped output streams to convert OutputStream to InputStream because the AWS java sdk does not allow puting objects on S3 using OutputStreams I'm using the code below, however, this will ...
0
votes
4answers
67 views

Concurrent Queue in Java that only retains the last item of each child thread

I have 1 main thread which starts up n child threads. Each of these child threads continually produce an new event and add it to the shared queue. That event represents the latest state of a complex ...
1
vote
1answer
23 views

java.lang.IllegalMonitorStateException error while using ReentrantLock?

I'm trying to implement blocking FIFO using ReentrantLock. Everything works fine except it is throwing IllegalMonitorStateException. When we try to release a resource that is not locked by the thread ...
-2
votes
1answer
32 views

Java map cache for highly multiple threads

Please suggest which map can be used for caching. My use case is a highly multi threaded server that I would like to synchronise put map but get map is not synchronised. My expectation is: if put ...
-1
votes
2answers
31 views

why the program hang up when using ArrayBlockingQueue

I'm having an issue when using an ArrayBlockingQueue. Here is my code: package study; import org.pmw.tinylog.Logger; import java.util.concurrent.ArrayBlockingQueue; import java.util.concurrent....
1
vote
2answers
48 views

In Java FutureTask if the task Times out, does the Task get Cancelled?

Assuming I have the following code snippet: FutureTask<?> f = new FutureTask<>(() -> { Thread.sleep(5000); return 1 + 2; }) myExecutor.execute(f); f.get(3, TimeUnit.SECONDS); From ...
-2
votes
1answer
17 views

Why does not the size of ArrayBlockingQueue object update?

I'm following an example at Chapter 23.6 Proceducer/Consumer Relationship: ArrayBlockingQueue ("Java - How to Program 10th). I tried to run example but I don't understand why "buffer.size()" is not ...
0
votes
0answers
68 views

Blocking set in Java

I need to use multiple threads, some of them are running, some of them are waiting until some other threads would wake them up. Lets say I have thread A, B, C, D and want to be able to wake/sleep any ...
0
votes
1answer
53 views

How to get a fixed sized Queue

I am trying to create a fixed size Queue in java, I only want to store maximum 10 objects in the Queue. However, the queue keeps on storing/adding objects and ignoring the if condition. my code: ...
0
votes
1answer
51 views

Thread safe of operation in one entry

I want to do operations like class A { } ConcurrentHashMap<A, Integer> map = new ConcurrentHashMap<>(); public void fun() { Integer count = map.get(Object); if (count != ...
3
votes
1answer
38 views

How to return future object from callable interface (internal working of executorService.submit)

I am trying to understand how future object is created when running the executorService.submit(Callable); For example lets say I create a thread pool in which I pass my implementation of callable ...
0
votes
0answers
30 views

JAVA ConcurrentLinkedQueue offer()

When I read the source code of offer() method in java.util.concurrent.ConcurrentLinkedQueue,jdk8-b132,I couldn't understand lines 344 to 352: 344 else if (p == q) 345 // We ...
0
votes
1answer
25 views

ConcurrentLinkedQueue shared across activities in Android

I'm working on an app that requires 4 queues of byte[] to be shared across multiple activities. I'm using ConcurrentLinkedQueue because I want them to be non-blocking because they will be ...
0
votes
3answers
70 views

Best way to implement graceful cancel for running async jobs in java

Let's say I have an interface like so for components in my application to run jobs - IJob { IResult execute(); void cancel(); } I want to set up my application so I run these jobs ...
2
votes
1answer
46 views

AtomicStampedReference.get() method: why parameter is array? [duplicate]

Some time ago I started to investigate java.util.concurrent package. And my question is about AtomicStampedReference class. The class has method public V get(int[] stampHolder) { ... } which ...
0
votes
0answers
35 views

Executor for grouped by key messages

I have sequential messages. Each message has a key (in my case I use locale as a key). I need some type of executor which allow me put this messages in different queues by the key and handle queues in ...
0
votes
1answer
54 views

How to Implement Map with Queue of objects

I am little confused how to implement the following output, { "finalOutput":{["test":{[],[],[],[],[],[],[],[],[],[]}, "test1":{[],[],[]....[]}, "test2":{[],[]....[]}]} } . For this ...
0
votes
2answers
68 views

Merging list concurrently - Which is better, CopyOnWriteArrayList or ConcurrentLinkedQueue?

Support there are a couple of threads running query tasks which each of them will return a list as result, which data structure will be faster to merge the results? ConcurrentLinkedQueue An ...
2
votes
1answer
42 views

How to make atomic a nested iterative operation on ConcurrentHashMaps?

I have a ConcurrentHashMap subscriptions that contain another object (sessionCollection) and I need to do the following iterative operation: subscriptions.values().forEach(sessionCollection -> ...
0
votes
2answers
41 views

Dynamically submitting tasks to ExecutorService based on condition

I am currently using ExecutorServices with fixed thread pool and submitting 3 tasks. ExecutorService executorService = Executors.newFixedThreadPool(3); Future<Object1> = executorService.submit(...
0
votes
1answer
64 views

Do atomics in Java guarantee ordering or only uniqueness?

When executing the following snippet I'm seeing that results are getting properly and uniquely incremented however they are printed out of order (as shown below): import java.util.concurrent.atomic....
3
votes
1answer
62 views

Java 7: How to execute parallel tasks in batches?

I have three web-service calls that can run in parallel. Hence, I'm using a fixed pool of 3 threads to run them. Now I want to process a couple more web-service calls, that can run in parallel, but ...
1
vote
3answers
68 views

Understanding of coordination for Java volatile fields' reads & writes across threads

I have the following code: private volatile boolean run = true; private Object lock =new Object(); ......... Thread newThread = new Thread(new Runnable() { @Override public void ...
2
votes
3answers
99 views

Is it safe to use AtomicBoolean for database locking in Scala/Java?

I have an application where I want to ensure that a method is called at most once concurrently, say when updating user balance in a database. I am thinking of using the following locking mechanism: (...
1
vote
0answers
41 views

Wrapping a concurrent collection

I have a class where I'm wrapping Java's ConcurrentLinkedQueue collection. I have a method called addToQueue that takes a value and inserts that value into the ConcurrentLinkedQueue. Does it matter ...
1
vote
3answers
64 views

ConcurrentHashMap putIfAbsent first time

I have a ConcurrentHashMap and a method that puts a String in the map, then I do some actions in a synchronized block based on the inserted value. putIfAbsent returns the previous value associated ...
1
vote
0answers
69 views

Using asynchronous methods in Java spark routes

I want to call a certain service using unirest inside my route which is implemented using Java spark. Is there anyway to return a Future and return the response only when it's finished?
-1
votes
1answer
47 views

Java Inter Thread Communication

I want to create a counter in a new Thread that has a method to get the value of the counter while the thread is running. How can I do it in an easy way?
4
votes
1answer
115 views

Implementing a dynamic File Transfer Controller using ThreadPoolExecutor in Java

I recently had to implement a Controller that's transfering files from A to B. There are about 8000 files with 1-2 mb size each. If one file transfer succeeds, create another thread. ( currently ...
0
votes
1answer
44 views

Short lived ExecutorService for async processing

I have an method that can execute asynchronous request in fire and forget fashion. Method is implemented as following : private void publishWorkItem(final Object payload, final ...
-1
votes
2answers
67 views

What are disadvantages of using ThreadPoolExecutor as queue?

For conventional Producer-Consumer problem, we can use ExecutorService as queue. What are disadvantages of it? Is it less efficient? Because creation of thread is costly. executor = Executors....
1
vote
1answer
56 views

How does making a field as final on an object avoids a thread seeing a null reference on that same object?

An abstract/snippet from Java Concurrency In Practice- // Unsafe publication public Holder holder; public void initialize(){ holder = new holder(42); } Two things can go wrong with improperly ...
0
votes
2answers
45 views

Concurrent access of AtomicMarkableReference compareandset method and get method

The compareAndSet() method of AtomicMarkableReference of Java works atomically. So, no two such methods can run concurrently on same object. However, if one of the thread is executing the ...
0
votes
0answers
23 views

Creating an immutable snapshot of a ConcurrentHashMap in a thread-safe manner?

I have the following two classes: public class PersonStore { private final ConcurrentHashMap<LocalDate, Person> personGroup = new ConcurrentHashMap<>(); public void add(LocalDate ...
0
votes
1answer
20 views

Why CountDownLatch getCount method returns Long datatype? [duplicate]

The constructor of CountDownLatch accepts the count in Integer datatype. Then, while fetching the remaining count why it returns as Long datatype?
0
votes
1answer
17 views

Blocking Awaitable instances with Duration.Inf, best practice?

We knew this piece of code: Await.result(someFuture, Duration.Inf) If I put a finite value of duration say 3 seconds, once expired, it throws TimeOutException. How about Duration.Inf, I am afraid ...
2
votes
3answers
51 views

puzzled when using synchronized lock [closed]

See below code, this puzzles me, in class DynamicPropertyFactory, it locks ConfigurationManager.class, as my understanding, the lock works only in the class or the instance itself. How to understand ...
0
votes
1answer
34 views

Check failure of putIfAbsent

Is this a valid code to write,if I wish to avoid unnecessary contains call? I wish to avoid a contains call on every invocation,as this is highly time sensitive code. cancelretryCountMap.putIfAbsent(...