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
3
votes
1 answer

Runnable locked (park) using ExecutorService and BlockingQueue

Note: I understand the rules site, but I can't to put all code (complex/large code). I put a DIFFERENT (all the real code is too much and you don't need here) code in Github but reproduces the Problem (the main class is…
joseluisbz
  • 1,491
  • 1
  • 36
  • 58
3
votes
1 answer

How to Properly Terminate a Thread which is Blocking (Lparallel Common Lisp)

In the Lparallel API, the recommended way to terminate all threaded tasks is to stop the kernel with (lparallel:end-kernel). But when a thread is blocking—eg, with (pop-queue queue1) waiting for an item to appear in the queue—it will still be active…
davypough
  • 1,847
  • 11
  • 21
3
votes
1 answer

How does corePoolSize=0 work for ThreadPoolExecutor?

The definition for ExecutorService.newCachedThreadPool() is public static ExecutorService newCachedThreadPool(ThreadFactory threadFactory) { return new ThreadPoolExecutor(0, Integer.MAX_VALUE, 60L,…
Chin
  • 19,717
  • 37
  • 107
  • 164
3
votes
0 answers

Why only ArrayBlockingQueue and SynchronousQueue have fairness policy?

Speaking about all classes implementing interface BlockingQueue, only ArrayBlockingQueue and SynchronousQueue have fairness policy. Besides, it seems that in all other BlockingQueue classes "fairness is false" meaning that any thread blocked first…
Code Complete
  • 3,146
  • 1
  • 15
  • 38
3
votes
1 answer

DelayQueue unexpected behavior. DrainTo deletes from the queue only 1 expired item

I want to iterate through unexpired elements in my DelayQueue. The class Transaction implements Delayed, and has a field timestamp, which represents the timestamp of a transaction when it was originated in UTC (not the current timestamp) public…
3
votes
2 answers

Wait for consumer to finish task before others can start

I have a Java application that traverses a tree-like folder structure and ultimately deletes the entire folder structure. For this, I am using a Blocking Queue with one producer (traverses a tree and puts paths to files that need to be deleted) and…
3
votes
1 answer

How can I implement a blocking queue with primive types?

Is there a Java native implementation which uses a blocking queue with primitive types? If not, how can I build one? I want to use blocking queue without boxing and unboxing when using primitives types. I check the trove assets, but it doesn't…
user5109370
3
votes
2 answers

BoundedPriorityBlockingQueue - thread safe, blocking and bounded?

is there a priority-queue in Java which acts like LinkedBlockingQueue? PriorityBlockingQueue is not blocking because it is unbounded.
barracuda317
  • 608
  • 7
  • 24
3
votes
2 answers

Java BlockingQueue take() in a while loop

I have a BlockingQueue which is being populated by a thread with put(). But I am confused on how to do take() for the BlockingQueue. Currently I implemented it this way: String link; try { while(!(link = links.take()).isEmpty()) { …
davidchoo12
  • 1,261
  • 15
  • 26
3
votes
2 answers

When does PriorityBlockingQueue sort the elements?

I have a PriorityBlockingQueue which contains a list of elements. I have implemented the Comparable interface and overrided the compareTo() in order to define which element is less, equal o greater than other. So I am wondering how does Priority…
Willy
  • 9,848
  • 22
  • 141
  • 284
3
votes
1 answer

Reading from multiple BlockingQueues within a single thread

I have three Java's LinkedBlockingQueue instances and I'd like to read from them (take operation) only using one thread. The naive approach is to have one thread per queue. Is there anything like the UNIX select system call for blocking queues in…
3
votes
5 answers

how to terminate retrieval from a blocking queue

I have some code where i execute a several tasks using Executors and a Blocking Queue. The results have to be returned as an iterator because that is what the application that i work on expects. However, there is a 1:N relationship between the task…
Asim
  • 869
  • 1
  • 10
  • 17
3
votes
2 answers

Mechanisms for creating long-running process

Are there alternative mechanism(s) for creating a long-running process besides running an infinite loop? The common pattern seems to be this: while True: # Check for some condition or waiting for some event # Do some processing …
skyork
  • 7,113
  • 18
  • 63
  • 103
3
votes
1 answer

Run computation on only the most recent, asynchronously updating data

Java Wizards! I'd like to implement the following requirements as efficiently as possible in Java. Every microsecond counts. The tl;dr version is I have a some computation that needs to run on fresh data. As soon as the data changes, the…
3
votes
2 answers

Java BlockingQueue produces/consumes not properly

I'm working on a project where I need to retrieve Twitter messages using the TwitterAPI, process them and store them in a database. I am using Producer/Consumer BlockingQueue where the elements act as follows: Producer : retrieves the Twitter…
RazorAlliance192
  • 722
  • 9
  • 23