Questions tagged [java.util.concurrent]

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.

java.util.concurrent is a core 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.

Main components include:

  • Executors
  • Queues
  • Timing
  • Synchronizers, Semaphores, CountDownLatch
  • Concurrent Collections

More information is available at the JavaDoc description

1396 questions
0
votes
1 answer

java.util.concurrent.LinkedBlockingQueue is not FIFO?

The brief description of java.util.concurrent.LinkedBlockingQueue says it is a FIFO queue, which means if thread A adds a bunch of entries (a1, a2, ... an) into the queue first and then thread B adds some more stuff into the queue (b1, b2, ... bm),…
Jim
  • 161
  • 2
  • 10
0
votes
1 answer

Waiting callback without pausing calling thread. Am I doing this right?

public class Threadz implements Callable{ private boolean flag = false; @Override public String call() throws Exception { // TODO Auto-generated method stub for(int i = 0; i < 3; i++){ …
tambalolo
  • 1,035
  • 3
  • 14
  • 30
0
votes
1 answer

java.util.concurrent multi-threading

I recently started messing with the java.util.concurrent, and I would like if someone could point out flaws or bad habits in my code. The program runs until a time out is reached, then outputs all the tasks that completed. Should I be using…
EdQ3
  • 31
  • 1
  • 7
0
votes
3 answers

How to use SynchronousQueue appropriately in producer-consumer model?

I wrote a test example of using SynchronousQueue in producer-consumer model. But it doesn't work well. Below are my codes: public class QueueTest { String input; int pos; BlockingQueue queue; volatile boolean exitFlag; …
JackWM
  • 10,085
  • 22
  • 65
  • 92
0
votes
3 answers

How could I integrate executors here? Or how could I improve this threading pool?

Currently I have a construct that does the following: An X number of threads (X being a configurable variable from the user) are all started and await for a task to become available. The threads block waiting in a BlockingQueue. Another thread(s)…
Cratylus
  • 52,998
  • 69
  • 209
  • 339
0
votes
1 answer

Pass parameter to Call method in Java.util.Concurrent

i am new to the high level Java.util.Concurrent package , what i am trying to do is read multiple text files at the same time using a thread pool. I need a way to pass the file name as an argument to my implementation of the call method . Something…
user1203861
  • 1,177
  • 3
  • 15
  • 19
0
votes
3 answers

Why do blocking library methods often respond to interruption by calling static interrupted() instead of instance method isInterrupted()?

Consider the following code from java.util.concurrent.locks.AbstractQueuedSynchronizer as one of the many examples of the idea presented in the title: 1258 public final boolean tryAcquireSharedNanos(int arg, long nanosTimeout) throws Interrupted…
Geek
  • 26,489
  • 43
  • 149
  • 227
0
votes
1 answer

Multithreading inside an EJB/MDB

Is there a way to run multiple threads inside a single EJB execution? What I'm trying to do is essentially an ETL process: the onMessage method of an MDB (@MessageDriven) will run a query, then kick off multiple threads to insert rows into some…
wrschneider
  • 17,913
  • 16
  • 96
  • 176
0
votes
3 answers

What method is submitting the task to the Executor framework in the code below?

Please refer to the following code of from the Javadoc of Future class: FutureTask future = new FutureTask(new Callable() { public String call() { return searcher.search(target); }}); …
Inquisitive
  • 7,476
  • 14
  • 50
  • 61
0
votes
2 answers

How to implement asynchronyous response?

I have controller with method that blocks the Play server thread due to very slow Database query. I need to implement controller method in a way that it don't block the thread. I have read documentation:…
Roman
  • 1,920
  • 2
  • 17
  • 17
0
votes
1 answer

how can i handle CancellationException in java concurrent programming?

I am using java.util.concurrent package to create a parallel program. I have 2 threads: thread-1 which invokes webservice method-1, and thread-2 which invokes webservice method-2. I am specifying a thread execution timeout - suppose if thread-1…
rev
  • 77
  • 1
  • 8
0
votes
3 answers

How can specify Thread Execution in Concurrent java programming?

I am using Callable, Executor and Future objects to invoke webservices in parallel from separate threads. After having executed all my webservice calls, I display the results in jsp. Here I have a doubt: if one of the webservice calls fails, how can…
rev
  • 77
  • 1
  • 8
0
votes
2 answers

is All threads will start in same time in java concurrency programming?

In my program i am creating 2 tasks. These tasks implement the Callable interface. I am passing these to 2 threads to execute Thread pool class. My question is will these 2 threads start in same time? In java concurrency programming do all threads…
rev
  • 77
  • 1
  • 8
0
votes
3 answers

Does a "private" modifier also ensure Thread safety in Java

Reading through this excellent article about safe construction techniques by Brain Goetz, I got confused by a comment given inside the listing 5. Here is the code snippet: public class Safe { private Object me; private Set set = new HashSet(); …
Inquisitive
  • 7,476
  • 14
  • 50
  • 61
-1
votes
3 answers

class to handle concurrent data insertion in java

There will be 500+ threads concurrently uploading an unique object to a bucket all the time. In this case, which data structure/class i should use to implement bucket in java. FYI: I tried using ArrayList, Vector, ConcurrentHashMap,…
krishna
  • 807
  • 2
  • 11
  • 19