Questions tagged [blockingqueue]

A queue data structure that that waits (suspends the current thread) for the queue to become non-empty when retrieving an element and for space to become available in the queue when storing an element.

A queue data structure that waits (suspends the current thread) for the queue to become non-empty when retrieving an element, or for space to become available in the queue when storing an element.

References

458 questions
9
votes
1 answer

SynchronousQueue in ThreadPoolExecutor

I'm trying to understand the behavior of queues in ThreadPoolExecutor. In the below program, when I use LinkedBlockingQueue, I can submit only one task to the thread pool at a time. But if I replace the LinkedBlockingQueue with SynchronousQueue, I…
UnahD
  • 867
  • 2
  • 10
  • 25
9
votes
3 answers

How to immediately release threads waiting on a BlockingQueue

Consider a BlockingQueue and a few threads waiting on poll(long, TimeUnit) (possibly also on on take()). Now the queue is empty and it is desired to notify the waiting threads that they can stop waiting. The expected behaviour is to have either null…
Joel Shemtov
  • 3,008
  • 2
  • 22
  • 22
9
votes
4 answers

How to remove elements from a queue in Java with a loop

I have a data structure like this: BlockingQueue mailbox = new LinkedBlockingQueue(); I'm trying to do this: for(Mail mail: mailbox) { if(badNews(mail)) { mailbox.remove(mail); } } Obviously the contents of the loop interfere…
Josh
  • 635
  • 2
  • 7
  • 12
8
votes
2 answers

How to wait on multiple blocking queues in parallel?

I have two separated blocking queues. The clients usually use either the first of the second blocking queue to retrieve elements to be processed. In some case, the clients are interested in elements from the two blocking queues, whichever queue…
user4444533
7
votes
2 answers

How long a blocking queue will wait for an element to dequeue?

I'm using a blocking queue implementaion in my program.I would like to konw how long the thread will wait for a element to dequeue.? My client thred polls fro response, my server thread offers message. My code is as follows; private…
Ratha
  • 9,434
  • 17
  • 85
  • 163
6
votes
3 answers

Java: Producer = Consumer, how to know when to stop?

I have several workers, that use ArrayBlockingQueue. Every worker takes one object from queue, process it, and in result can get several objects, that will be put into queue for further processing. So, worker = producer + consumer. Worker: public…
Oleg Golovanov
  • 905
  • 1
  • 14
  • 24
6
votes
3 answers

Blocking queue implementation in Haskell

In java, there is nice package java.util.concurrent which holds implementation for BlockingQueue interface. I need something similar in Haskell, so it will be able to maintain fixed size of queue in memory block read operations when queue is empty…
jdevelop
  • 12,176
  • 10
  • 56
  • 112
6
votes
3 answers

C++ pthread blocking queue deadlock (I think)

I am having a problem with pthreads where i think i am getting a deadlock. I have created a blocking queue which I thought was working, but after doing some more testing I have found that if i try and cancel multiple threads that are blocking on the…
vimalloc
  • 3,869
  • 4
  • 32
  • 45
6
votes
2 answers

Python: Kombu+RabbitMQ Deadlock - queues are either blocked or blocking

The problem I have a RabbitMQ Server that serves as a queue hub for one of my systems. In the last week or so, its producers come to a complete halt every few hours. What have I tried Brute force Stopping the consumers releases the lock for a few…
Adam Matan
  • 128,757
  • 147
  • 397
  • 562
6
votes
2 answers

How to handle InterruptedException of BlockingQueue?

I have a code similar to this which is inside run() method of a Runnable and multiple instances of that Runnable get launched, do{ try{ String contractNum=contractNums.take(); }catch(InterruptedException e){ …
Sabir Khan
  • 9,826
  • 7
  • 45
  • 98
6
votes
2 answers

Using ArrayBlockingQueue makes the process slower

I just recently used ArrayBlockingQueue for my multi-thread process. But it seemed like it slowed down rather than speeding up. Can you guys help me out? I'm basically importing a file (about 300k rows) and parsing them and storing them in the…
Kara
  • 69
  • 6
6
votes
2 answers

JMSException InterruptedIOException - the producer thread get interrupted

I am getting JMS Exception and it seems queue does not exit or it's not finishing the task. Messages are asynchronous and it work fine most of the time but sometimes get below exception. It seems listener is keep listening at other side but at…
Santosh
  • 782
  • 4
  • 15
  • 38
6
votes
2 answers

BlockingQueue and putAll

Does anybody know why java's BlockingQueue does not have a putAll method? Is there a problem with such a method? Any good ways around this problem without having to completely re-implement BlockingQueue?
Jeff Wu
  • 83
  • 4
6
votes
2 answers

Java: Thread producer consumer what is the most efficient way to wait for data to be produced

When using BlockingQueue to consume data that is produced what is the most efficient method for waiting for the data to appear? Scenario: Step 1) The data list will be a data store where timestamps are added to. These timestamps are required to be…
perkss
  • 1,037
  • 1
  • 11
  • 37
6
votes
3 answers

Suspend consumer in producer/consumer pattern

I have producer and consumer connected with BlockingQueue. Consumer wait records from queue and process it: Record r = mQueue.take(); process(r); I need pause this process for a while from other thread. How to implement it? Now I think implement it…
HotIceCream
  • 2,271
  • 2
  • 19
  • 27
1 2
3
30 31