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

Updating an custom Object stored in blocking priority queue

I have a blocking priority queue which stores Objects of type Message, message has String[] data = new String[10]. Now I have to iterate over whole blocking Queue, check if its Object message's 2nd element is equal to 6th element of an incoming…
Yogesh
  • 1,307
  • 3
  • 13
  • 18
1
vote
1 answer

How does a ThreadPoolExecutor that is created using the constructor with BlockingQueue as an argument, enqueue Callables?

The constructor for ThreadPoolExecutor has the type argument for the BlockingQueue as Runnable. Let's suppose I have a ThreadPoolExecutor declared like this ThreadPoolExecutor customThreadPool = new ThreadPoolExecutor(numberOfAvailableProcessors, …
Shankha057
  • 1,296
  • 1
  • 20
  • 38
1
vote
3 answers

why is there a while loop in put() of LinkedBlockingQueue

public void put(E e) throws InterruptedException { if (e == null) throw new NullPointerException(); int c = -1; Node node = new Node(e); final ReentrantLock putLock = this.putLock; final AtomicInteger count = this.count; …
Vic
  • 99
  • 1
  • 7
1
vote
0 answers

Is there a way to hold a collection of "messages" upto size 1 MB and write the result to JSON/CSV file

I have a blocking queue which keep getting messages through some app, now In asp.net app I tried to consume the queue and write the output into CSV/JSON file. Here I want to hold messages up to 1MB which receive from blocking queue and then write it…
user584018
  • 10,186
  • 15
  • 74
  • 160
1
vote
1 answer

Read lines from Socket and put each into BlockingQueue

Can anyone provide examples in Java, or advise about implementing a class which asynchronously reads lines from a socket and puts each line into a BlockingQueue. Assume the socket is connected, and the BlockingQueue and consumer already…
Jack
  • 1,477
  • 15
  • 20
1
vote
3 answers

ArrayBlockingQueue NoSuchElementException

Just for learning, I have written the following code for custom thread pool referring and editing the code shown here. As shown in the code I am using ArrayBlockingQueue for task queue. Code: import java.util.ArrayList; import…
Alok Dubey
  • 419
  • 4
  • 13
1
vote
2 answers

Spring Autowired Shared Queue NullPointerException

I'm using Spring for the first time and am trying to implement a shared queue wherein a Kafka listener puts messages on the shared queue, and a ThreadManager that will eventually do something multithreaded with the items it takes off the shared…
A.A.
  • 402
  • 1
  • 4
  • 19
1
vote
2 answers

Wait on Multiple Blocking Queues

How to wait on multiple Blocking Queues in Java? For example, if have a customer who wants to enter into a waiting Lounge. There are 3 waiting Lounges and each lounge has a fixed number of seats. Considering this a concurrent programming question,…
Chandan S R
  • 61
  • 1
  • 8
1
vote
1 answer

Wait for all blocking queue elements to be processed after they are taken out

In the following scenario, the finalizer thread must wait for the consumer thread to process all queue elements in order to finish execution: private final BlockingQueue queue = new LinkedBlockingQueue<>(); private final Object queueMonitor…
spongebob
  • 8,370
  • 15
  • 50
  • 83
1
vote
1 answer

why all producer threads also exit when comsumer threads all exit

I am running the below code, and I have one question: why do all producer threads also exit when the consumer threads all exit. Here is the code: public class NumbersConsumer implements Runnable { private final BlockingQueue queue; …
Endy Liu
  • 11
  • 1
1
vote
1 answer

TypeScript: Large memory consumption while using ZeroMQ ROUTER/DEALER

We have recently started working on Typescript language for one of the application where a queue'd communication is expected between a server and client/clients. For achieving the queue'd communication, we are trying to use the ZeroMQ library…
1
vote
0 answers

queue.add(...) return true but no element is added to the BlockingQueue

I try to write a method taking a BlockingQueue< List < String[]> > and a file path as a String, and adding to the queue each line of the file as an ArrayList containing the line as a String[]. (I will later add more String[] in each…
Akita
  • 287
  • 2
  • 8
1
vote
0 answers

What is the reason to implement ArrayBlockingQueue with one lock on tail and head?

I am reading Java Concurrency in practice, now I'm on page about comparison LinkedBlockingQueue with ArrayBlockingQueue and I've found this text This test suggests that LinkedBlockingQueue scales better than ArrayBlockingQueue.This may seem odd at…
Alex
  • 3,923
  • 3
  • 25
  • 43
1
vote
1 answer

BlockingQueue offer method doesn't add item to list sometime

I am using BlockingQueue in a multi threading system where a synchronized block adds items to the list. Sometimes it does not add items to the list, items that it misses are random.I tried to add following line to the code and then it never missed…
Chirag
  • 57
  • 6
1
vote
1 answer

setup ordering in priority blocking queue

I have a PriorityBlockingQueue in which I am adding SocketHolder as shown below. And let's say current datacenter where this code is running is abc. We have three datacenters abc, def and pqr. private static final PriorityBlockingQueue
user1950349
  • 4,738
  • 19
  • 67
  • 119