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

blockingqueue and Spring - how do I start thread pool at startup?

I have a spring application that use blockingqueue to run producer-consumer design. Basically when user makes an API call using REST controller, it adds a work to blockingqueue and background thread will consume the queue as soon as it's arrived. I…
hinewwiner
  • 627
  • 13
  • 25
4
votes
2 answers

Are there any implementations of concurrent lock-free blocking queues?

I'm aware of blocking-queues and lock-free queues, a great example of those implementations being provided by Scott et al., but are there any implementations of a lock-free-blocking-queue? In a lock-free-blocking-queue the dequeue will require no…
Kiril
  • 39,672
  • 31
  • 167
  • 226
4
votes
1 answer

how to give priority to the threads waiting in a semaphore?

I have used a semaphore to restrict the number of threads accessing a function. I want the thread to be awakened next should be chosen by some priority which i will be giving,not by default way that semaphore awaken's them ? How can we achieve this…
4
votes
4 answers

Java's BlockingQueue design question

the method java.util.concurrent.BlockingQueue.add(E e)'s JavaDoc reads: boolean add(E e) Inserts the specified element into this queue if it is possible to do so immediately without violating capacity restrictions, returning true upon …
Manuel Araoz
  • 15,962
  • 24
  • 71
  • 95
4
votes
1 answer

What could be the locking / unlocking reasoning in PriorityBlockingQueue?

I have been reading the source code of PriorityBlockingQueue in Java and I was wondering : why is the tryGrow() method releasing the lock acquired during the offer() method, just to do its thing non-blocking, and then block again when ready to…
Belun
  • 4,151
  • 7
  • 34
  • 51
4
votes
2 answers

Concurrently iterating over a BlockingQueue

In an application which uses a BlockingQueue, I am facing a new requirement that can only be implemented by iterating over the elements present in the queue (to provide info about the current status of the elements in there). According to the API…
emu
  • 399
  • 2
  • 6
4
votes
1 answer

Is it safe to put a stateless callback into BlockingQueue?

I've got the following pretty straightforward callback interface and a POJO class: public interface Action{ public void doAction(); } public class Person{ private String name; private String address; //...etc //GET, SET,…
St.Antario
  • 26,175
  • 41
  • 130
  • 318
4
votes
3 answers

Can I implement blocking queue using Semaphore in Java?

I wonder if it is possible to use Semaphore to implement blocking queue? In the below codes, I use one Semaphore to protect the critical section, and two more Semaphore objects to track the number of empty slots and filled objects. public class…
Jack Chen
  • 79
  • 1
  • 7
4
votes
2 answers

addAll() in LinkedBlockingQueue is thread safe (and solution if it's not)?

Quoting the documentation: "BlockingQueue implementations are thread-safe. All queuing methods achieve their effects atomically using internal locks or other forms of concurrency control. However, the bulk Collection operations addAll, containsAll,…
justHelloWorld
  • 6,478
  • 8
  • 58
  • 138
4
votes
2 answers

BlockingQueue decorator that logs removed objects

I have a BlockingQueue implementation that's being used in a producer-consumer situation. I would like to decorate this queue so that every object that's taken from it is logged. I know what the straightforward implementation would look like: simply…
Edward Dale
  • 29,597
  • 13
  • 90
  • 129
4
votes
1 answer

put(s) and take(s) in BlockingQueue Java

Here is the example. class Factory { Queue queue = new LinkedBlockingQueue(); public Object consume() { queue.take(); } public void produce() { for (int i = 0; i < 2; i++) { queue.put(new…
Shahin
  • 93
  • 1
  • 8
4
votes
1 answer

What does "less predictable performance of LinkedBlockingQueue in concurrent applications" mean?

For the logging feature I am working on, I need to have a processing thread which will sit waiting for jobs and execute them in batches when the count reaches or exceeds certain number. Since it is a standard case of producer consumer problem, I…
vk239
  • 1,014
  • 1
  • 12
  • 30
3
votes
2 answers

Why LinkedBlockingQueue's head is not private?

I'm reading LinkedBlockingQueue code (JDK8u), and I find LinkedBlockingQueue's head field is not private, but last field is private. I can't find any particular opration with head . So why not set head to private ? /** * Head of linked list. *…
fjdingsd
  • 31
  • 4
3
votes
0 answers

How to keep running a specific number of java processes in Linux shell?

I have to run hundreds of java processes in Linux for my project. But running so many processes simultaneously is impossible due to scarcity of system resources. That being said, I have to partition all the processes into continuous blocks, each…
Jonathan Zhou
  • 89
  • 1
  • 5
3
votes
2 answers

Why ArrayBlockingQueue constructor use ReentrantLock for visibility?

The code is from ArrayBlockingQueue,JAVA 8. The comment says:Lock only for visibility, not mutual exclusion. final Object[] items; int putIndex; int count; public ArrayBlockingQueue(int capacity, boolean fair, …