Skip to main content
129 votes
11 answers
46k views

I've been frustrated for some time with the default behavior of ThreadPoolExecutor which backs the ExecutorService thread-pools that so many of us use. To quote from the Javadocs: If there are more ...
Gray's user avatar
  • 117k
100 votes
5 answers
48k views

I have a class that takes objects from a BlockingQueue and processes them by calling take() in a continuous loop. At some point I know that no more objects will be added to the queue. How do I ...
MCS's user avatar
  • 22.6k
85 votes
3 answers
38k views

When to prefer LinkedBlockingQueue over ArrayBlockingQueue? Which data structure to use among LinkedBlockingQueue and ArrayBlockingQueue when: You want an efficient read and write should have lesser ...
Vaibhav Gupta's user avatar
73 votes
6 answers
63k views

I have a single thread producer which creates some task objects which are then added into an ArrayBlockingQueue (which is of fixed size). I also start a multi-threaded consumer. This is build as a ...
Shivan Dragon's user avatar
70 votes
6 answers
42k views

new SynchronousQueue() new LinkedBlockingQueue(1) What is the difference? When I should use SynchronousQueue against LinkedBlockingQueue with capacity 1?
Anton's user avatar
  • 6,109
69 votes
6 answers
64k views

I am working on a multithreaded project in which I need to spawn multiple threads to measure the end to end performance of my client code, as I'm doing Load and Performance testing. So I created the ...
user avatar
66 votes
6 answers
54k views

In particular, I am looking for a blocking queue. Is there such a thing in C++11? If not, what are my other options? I really don't want to go down to the thread level myself anymore. Way too error-...
fredoverflow's user avatar
47 votes
4 answers
41k views

What scenarios is it better to use an ArrayBlockingQueue and when is it better to use a LinkedBlockingQueue? If LinkedBlockingQueue default capacity is equal to MAX Integer, is it really helpful to ...
Java_Jack's user avatar
  • 585
41 votes
8 answers
16k views

I have a blocking queue of objects. I want to write a thread that blocks till there is a object on the queue. Similar to the functionality provided by BlockingQueue.take(). However, since I do not ...
rouble's user avatar
  • 18.4k
40 votes
2 answers
51k views

When consuming values from a Queue in an infinite loop -- what would be more efficient: Blocking on the Queue until a value is available via take() while (value = queue.take()) { doSomething(value); }...
isapir's user avatar
  • 24k
32 votes
11 answers
24k views

I’m using java.util.concurrent.BlockingQueue in a very simple producer-consumer scenario. E.g. this pseudo code depicts the consumer part: class QueueConsumer implements Runnable { @Override ...
Lachezar Balev's user avatar
28 votes
5 answers
21k views

Suppose I have a task that is pulling elements from a java.util.concurrent.BlockingQueue and processing them. public void scheduleTask(int delay, TimeUnit timeUnit) { scheduledExecutorService....
parkr's user avatar
  • 3,228
28 votes
6 answers
34k views

I'm looking for a way to block until a BlockingQueue is empty. I know that, in a multithreaded environment, as long as there are producers putting items into the BlockingQueue, there can be ...
gd1's user avatar
  • 11.4k
27 votes
4 answers
15k views

I have a requirement where I need to read from a set of Blocking queues. The blocking queues are created by the Library I am using. My code has to read from the queues. I don't want to create a reader ...
Nipun Talukdar's user avatar
21 votes
5 answers
12k views

The JavaDoc for ThreadPoolExecutor is unclear on whether it is acceptable to add tasks directly to the BlockingQueue backing the executor. The docs say calling executor.getQueue() is "intended ...
user avatar

15 30 50 per page
1
2 3 4 5
31