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
1
vote
2 answers

Concurrent version of Queue needs exceptions

I am writing a custom queue implementing the queue interface. This implementation is thread safe and blocks on certain occasions. The normal Queue interface does not mention Exceptions, therefore I can't throw any InterruptedException in my…
Franz Kafka
  • 10,623
  • 20
  • 93
  • 149
1
vote
2 answers

java concurrency: BlockingQueue based producer/consumer does not seem to work well with compound actions that needs synchronized code block?

It comes to a surprise to me when I am trying to implement some compound actions with a BlockingQueue based producer/consumer pattern, which makes me think I most likely have missed something obvious. 1. In short I need my consumer to make…
1
vote
2 answers

concurrent application not as fast as a singlethreaded

I've implemented a pipeline approach. I'm going to traverse a tree and I need certain values which aren't available beforehand... so I have to traverse the tree in parallel (or before) and once more for every node I want to save values…
Johannes
  • 2,021
  • 2
  • 23
  • 40
1
vote
1 answer

Preferable approach for waiting on empty BlockingQueue

I've got a multithreaded application with one thread putting items into a BlockingQueue and multiple threads taking items from it for procession. The question is about taking items from the queue, currently it's implemented like this: class…
1
vote
2 answers

Concurrent put calls on a BlockingQueue in Java

I know that concurrent adds to an stl queue in c++ can cause issues, and the way to solve this is adding a mutex lock around all add/remove calls. But I am programming in Java at the moment, and I'm using BlockingQueue. The documentation only says…
K Mehta
  • 10,323
  • 4
  • 46
  • 76
1
vote
1 answer

How to solve producent consumer problem with capacity 1 using BlockingQueue?

I have to solve producent-consumer problem using BlockingQueue. I want it to be 1 element queue. So solution have to be: Produce 1 Consume 1 Produce 2 Consume 2 Produce 3 Consume 3 But it is: Produce 1 Produce 2 Consume 1 Consume 2 Produce 3 Produce…
MrFisherman
  • 720
  • 1
  • 7
  • 27
1
vote
2 answers

Blocking Queue implementation: Where's the race condition?

It's me and my BlockingQueue again... I rewrote it according to this article and this question. It sends some items and then crashes with an access violation. Here's the code: template bool DRA::CommonCpp::CTBlockingQueue::Push( T…
dario_ramos
  • 7,118
  • 9
  • 61
  • 108
1
vote
1 answer

Producer & Consumer is not printing answer in order

I am trying to write produce and consumer that should print output in below order consumer 1 produce 1 consumer 2 produce 2 But it's not giving outputs in order. To achieve order when using synchronized keyword, it's not printing even any…
1
vote
1 answer

Memory consumption in arrayBlockingQueue and linkedBlockingQueue

Say I make capacity of arrayBlockingQueue and linkedBlockingQueue both to 100. I add only 10 elements in each of them. Will array hold full capacity even though 90 elements are empty? I mean would it have 10 elements and 90 nulls? Another thing, how…
Ana Maria
  • 475
  • 2
  • 11
1
vote
3 answers

Why does thread pool takes tasks independenty and not concurrently?

I am trying to get the basics very strong about thread pool. I learnt that it internally uses blocking queue to 'steal' tasks and run them into given threads in pool. Meaning that if I had 10 tasks and 5 threads, it could run only 5 tasks at the…
Ana Maria
  • 475
  • 2
  • 11
1
vote
3 answers

What is the point of BlockingQueue not being able to work in synchronized Producer/Consumer methods?

When I first read about interface BlockingQueue I read that: Producer blocks any more put() calls in a queue if it has no more space. And the opposite, it blocks method take(), if there are no items to take. I thought that it internally works same…
Ana Maria
  • 475
  • 2
  • 11
1
vote
2 answers

Java BlockingQueue confusion

I am currently reading about Java BlockingQueue and this example is given on many websites for a simple implementation of the BlockingQueue. The code is simple but I am a bit confused. For example lets say we fill up the queue, then we try to…
user737163
  • 431
  • 3
  • 9
1
vote
2 answers

Blocking Queue poll method retuns null during multiple threads

We have implemented multithreading in our application using blockingqueue, executor framework and future. When ever user asks for some data, we submit a task to the executor framework which connects to database, queries data and streams the data…
PDJ
  • 69
  • 8
1
vote
0 answers

Can I call notifyAll before returning an object from a synchronized block?

I am new to multithreading and I am attempting to implement a unbounded queue. I know that notifyAll wakes up all the threads that are waiting on the object's monitor. But what happens if I return object immediately after waking up the threads. Will…
Tima M
  • 11
  • 2
1
vote
1 answer

Java take() Method of LinkedBlockingQueue is stuck, even if the Queue should not be empty

I'm writing Code for a Network Application. Therefor I'm using a LinkedBlockingQueue to store incoming messaged until they are consumed. The following code runs in it's own Thread and fills up the Queue: while(true) { String msg =…
user11318028