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
2
votes
0 answers

Blocking peek in BlockingQueue

I have seen few threads on how to simulate blocking peek, but my question is why is this method not provided by default? I have seen many threads asking for this, but is there an obvious work around for blocking peek, or is it not advisable to rely…
jay
  • 1,982
  • 2
  • 24
  • 54
2
votes
4 answers

Java Producer Consumer ArrayBlockingQueue deadlock on take()

In my app there are 2 phases, one download some big data, and the other manipulates it. so i created 2 classes which implements runnable: ImageDownloader and ImageManipulator, and they share a downloadedBlockingQueue: public class…
user2212726
  • 1,225
  • 3
  • 16
  • 23
2
votes
2 answers

queue.IsCompleted returns false even when the queue is empty?

The following code never return. Debugging shows that the queue.IsCompleted returns false even when the queue is empty. Did I miss anything? var workers = new Task[1]; using (var queue = new BlockingCollection(20)) { workers[0] =…
ca9163d9
  • 27,283
  • 64
  • 210
  • 413
2
votes
1 answer

blocking queue implementation

I've just implemented a custom blocking queue with an semaphore. for a reason i cant find, my queue isn't getting blocked by the semaphore when my queue is empty. here's my implementation: package poolThread; import java.util.LinkedList; import…
gil
  • 2,388
  • 1
  • 21
  • 29
2
votes
0 answers

Activemq queue consumers being blocked

I have the following architecture for integration in my system: 2 Mule instances (not in a Mule cluster, because of CE version) and 2 activemq instances configured in master-slave using shared database lock. There is a flow in Mule which has as…
user1093643
  • 251
  • 1
  • 3
  • 13
2
votes
1 answer

Memory usage by using BlockingQueue in ThreadPoolExecutor

I noticed the size of each Runnable object is around 600KB. I am using the BlockingQueue with fix size of 10000. From the logging message, I saw all the 9864 objects had put into the queue. I did not see any the memory usage drastically increased.…
2
votes
2 answers

Flow control on blocking queue and SocketChannel write

I have a blocking queue where multiple writers are writing. I want to put a transaction control mechanism where not more than, say, 50 writers(or near) can write per second. Is there a way I can achieve it? Edit 1: There is a similar requirement to…
Abhash Upadhyaya
  • 717
  • 14
  • 34
2
votes
1 answer

In Java, what happens if I leave DatagramPackets at the DatagramSocket?

I am building a networked application using DatagramSocket. I have a "network" thread whose sole job is to pull DatagramPacket objects from a DatagramSocket and place the data on a BlockingQueue. It does this as fast as it is able. The queue is…
sdgfsdh
  • 33,689
  • 26
  • 132
  • 245
2
votes
0 answers

MPSC queues: Handling List of CompletableFutures cleanly

Trying to implement list of tasks queueing to a blocking queue, asynchronously. A BlockingQueue that gets consumed batch wise by a single thread and reports completion of each task. For eg. 1) a web request generates a List that are queued to…
jknair
  • 4,709
  • 1
  • 17
  • 20
2
votes
2 answers

Is this BlockingQueue Thread safe?

I was trying myself on implementing a minimal thread safe blocking queue, what I came up with is: class BlockingQueue { private Queue myQueue = new Queue(); private SemaphoreSlim semaPhore = new SemaphoreSlim(0); public void…
trykyn
  • 451
  • 2
  • 9
2
votes
0 answers

Pass Variables using Blocking Queue

At the moment I am trying to make my program pass the variables xPos and yPos from the ChessBoard class to the makeMove() method in HumanPlayer. But at the moment it just gives null pointer exceptions in HumanPlayer. Can this be done with…
2
votes
1 answer

Java LinkedBlockingQueue source code confusion

I am reading Java LinkedBlockingQueue source code, and I have two questions about the put operation. public void put(E e) throws InterruptedException { if (e == null) throw new NullPointerException(); // Note: convention in all put/take/etc…
GarudaReiga
  • 1,057
  • 2
  • 9
  • 12
2
votes
3 answers

Multiple Producer Multiple Consumer Multithreading Java

I'm trying out Multiple Producer - Multiple Consumer use case of Producer-Consumer problem. I'm using BlockingQueue for sharing common queue between multiple producers/consumers. Below is my code. Producer import…
Saurabh Gokhale
  • 53,625
  • 36
  • 139
  • 164
2
votes
2 answers

Creating a Blocking Queue

Sometimes this implementation and execution of BlockingQueue just works. Sometimes it segfaults. Any idea why? #include using std::thread; #include using std::mutex; #include using std::cout; using std::endl; #include…
Chris Redford
  • 16,982
  • 21
  • 89
  • 109
2
votes
1 answer

Scala blocking queue, making proper wait

I have to implement a blocking and synchronized queue in scala. If I don't miss something, synchronizing is pretty simple, but for my queue to be blocking I could only think of that (which works) : def pop() : T = { this.synchronized { …
Théo Winterhalter
  • 4,908
  • 2
  • 18
  • 34