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.

blockingqueue
125 questions with no upvoted or accepted answers
Filter by
Sorted by
Tagged with
3 votes
0 answers
73 views

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 ...
Jonathan Zhou's user avatar
3 votes
0 answers
154 views

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 "...
Code Complete's user avatar
3 votes
1 answer
79 views

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 ...
Anaxagoras's user avatar
2 votes
0 answers
919 views

Single Producer, Multiple Blocking Queues, Multiple Consumers

Producer looks at each message type and routes to any ArrayBlockingQueue based on availability of space in that Queue. There are only two types of messages Type 1 or Type 2. A given queue can contain ...
user2116243's user avatar
2 votes
1 answer
562 views

Continuously submitting Runnable tasks to ExecutorService until work is done, getting java.util.concurrent.RejectedExecutionException

My multi-threaded class is supposed to carry out three operations – operation1, operation2, and operation3 – on a number of objects of the class ClassA, where each type of operation is dependant on ...
hi_tech_jazz's user avatar
2 votes
0 answers
262 views

Is there a way to do a poll and offer in DelayQueue in synchronized way?

In my implementation I use DelayQueue to prevent too many concurrent access of my method. I found that DelayQueue use internal lock on both methods poll and offer, but in my case I need to do ...
Orest's user avatar
  • 6,668
2 votes
0 answers
532 views

Java BlockingQueue Consumer Multithread notworking

I have implemented a producer consumer problem using BlockingQueue. In this, producer post some tasks at different interval to blocking queue and multiple consumers take that task to process it. My ...
Piyush's user avatar
  • 388
2 votes
1 answer
74 views

ArrayBlockingQueue: Why global variables are not accessed directly?

In the ArrayBlockingQueue Implementation, Why the global variables are not accessed directly ? public class ArrayBlockingQueue<E> extends AbstractQueue<E> implements ...
Kamal Chandraprakash's user avatar
2 votes
0 answers
593 views

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 ...
jay's user avatar
  • 2,012
2 votes
0 answers
1k views

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 ...
user1093643's user avatar
2 votes
0 answers
501 views

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 ...
jknair's user avatar
  • 4,749
2 votes
0 answers
187 views

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 ...
John Sumner's user avatar
2 votes
2 answers
1k views

Android threads with queue vs Handler/Looper: which one is efficient?

I have a producer-consumer situation, where I want to decide between two mechanisms to implement it. It is an audio-recording/encoding case: The producer polls device microphone ,continuously, for the ...
Nazar Merza's user avatar
  • 3,404
2 votes
2 answers
840 views

C++ Blocking Queue Segfault w/ Boost

I had a need for a Blocking Queue in C++ with timeout-capable offer(). The queue is intended for multiple producers, one consumer. Back when I was implementing, I didn't find any good existing queues ...
Ben's user avatar
  • 7,762
2 votes
0 answers
141 views

BlockingQueue in ServletContextAttributeListener

I'm trying to transfer data (from a thread started in a ServletContextListener which is continuously adding data to the queue) to a ServletContextAttributeListener. The data from the queue needs to ...
Thomas's user avatar
  • 1,688
2 votes
2 answers
485 views

producer-consumer: how to know inform that prodcution completed

i have the following situation: Read data from database do work "calculation" write result to database I have a thread that reads from the database and puts the generated objects into a ...
beginner_'s user avatar
  • 331
2 votes
1 answer
1k views

Thousands of threads spawned from Java process... why?

I have a problem with a recent customer migration to Linux (64-bit) when running a Java process. The process is spawning thousands of threads most with an identifier of futex. I've looked up futex (...
Andy's user avatar
  • 193
1 vote
0 answers
171 views

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 ...
Tima M's user avatar
  • 11
1 vote
1 answer
1k views

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 ...
user avatar
1 vote
1 answer
2k views

Spring boot thread pool executor rest template behavior in case queueCapacity is 0 is decreasing performance for a rest apis application

I am stuck with a strange problem and not able to find out its root cause. This is my rest template thread pool executor : connectionRequestTimeout: 60000 connectTimeout: 60000 socketTimeout: ...
Sukh's user avatar
  • 498
1 vote
0 answers
131 views

Want to keep code from executing until user presses button (JavaFx Button)

I have a pretty simple game that I'm making (with a pretty basic gui) and it uses JavaFx buttons to choose what will happen. Each button has a message and an ActionEvent tied to it. When I run the ...
ReidBrostoff's user avatar
1 vote
1 answer
1k views

Inserting 10 MILLION RECORDS INTO DB using task executor in java

My requirement is to encrypt personal identification columns of table. For which I have written a small code which selects the data in batches and insert into new table with few extra columns. ...
Muddassir Rahman's user avatar
1 vote
0 answers
212 views

Single producer - multiple different consumers

I'm doing an uni project about a computer system intended to be used in an hospital. I have a TreeSet of Patient, where all the patients recovered in the hospital are stored. The class Patient has ...
Jas's user avatar
  • 21
1 vote
0 answers
48 views

Can my consumer become producer (apparently) for few cases

I am solving transaction polling case using producer-consumer problem using ExecutorService and BlockingQueue. I have a list of transactions, which I want to verify and take action. I am getting a new ...
impossible's user avatar
  • 2,440
1 vote
0 answers
106 views

How to block the provider util the blocking queue becomes empty?

In general, I want to block the provider of a blocking queue until the queue becomes empty, and then put a batch of elements into the queue. I find a relative question here: How to block until a ...
liubenxi's user avatar
1 vote
0 answers
149 views

LinkedBlockingQueue with one element - Reader/Writer Race Condition

LinkedBlockingQueue uses two separate ReentrantLocks, putLock and takeLock. This enables one reader and one writer to access the queue at the same time using the following methods: 1) poll() 2) take()...
Kans's user avatar
  • 392
1 vote
1 answer
371 views

Blocking Queue Take out of Order

I have a simple blocking queue containing Integers. In a multi thread environment I am taking and adding elements to the the back of the queue. BlockingQueue<Integer> test = new ...
J DOe's user avatar
  • 593
1 vote
1 answer
320 views

RejectedExecutionException occurs while using LinkedBlockingQueue(Integer.MAX_VALUE) in ThreadPoolExecutor

I'm using ThreadPoolExecutor with LinkedBlockingQueue(Integer.MAX_VALUE) for multiple tasks, but why it throws RejectedExecutionException when submit(Callable task) within 2000 tasks in websphere? ...
Joey's user avatar
  • 11
1 vote
0 answers
116 views

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 ...
user584018's user avatar
  • 10.8k
1 vote
2 answers
258 views

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. ...
Chandan S R's user avatar
1 vote
1 answer
1k views

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 ...
Abhijit Parkhi's user avatar
1 vote
0 answers
435 views

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[]. (...
Akita's user avatar
  • 287
1 vote
0 answers
578 views

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 ...
Alex's user avatar
  • 4,233
1 vote
1 answer
259 views

Little Law's: Concurrency

I had posted this question on a google forum but didn't get a definitive answer. Can someone verify if my understanding of Little's law is correct in the context of locking. Suppose I have a system ...
CaptainHastings's user avatar
1 vote
1 answer
94 views

How do I test cross-thread queue?

I am not 100% sure that this is SO-adequate question, but I guess it falls under "a specific programming problem". Tips to make it more SO-friendly are welcome. A bit of context In DLang there ...
Filip Malczak's user avatar
1 vote
0 answers
357 views

Java Queue BlockingQueue<Arraylist<Object>>

I am working on a program (mostly for learning) in which a producer thread will read in a file to an arraylist and then store this into a que, The consumer will then take this ArrayList and do some ...
SolutionFindingBrowser's user avatar
1 vote
0 answers
108 views

Blocking Queue Learning / Repeated Value Issue

I am running into some issues when creating a Producer/Consumer threaded process. So I used this test code to create a Producer and Consumer which correctly put() and take(). Consumer Code public ...
SolutionFindingBrowser's user avatar
1 vote
2 answers
1k views

Contains with a predicate (/find/search) for a java.util.concurrent.BlockingQueue?

The java.util.concurrent.BlockingQueue has a convenient contains method: /** * Returns {@code true} if this queue contains the specified element. * More formally, returns {@code true} if and only ...
WestCoastProjects's user avatar
1 vote
1 answer
433 views

Is Boost_lockFree_SPSC_queue is really variable sized and data loss free?

Hi I have planned to use boost SPSC queue. I have to have a listener which always listen for the incoming messages once it received it will put the message into a queue and return to wait again for ...
Kid's user avatar
  • 169
1 vote
0 answers
54 views

Blocking Queue Take() does not retrieve the item

I have the code below: @Override public boolean start() { boolean b = false; if (status != RUNNING) { LOGGER.info("Starting Auto Rescheduler Process..."); try { b =...
idipous's user avatar
  • 2,910
1 vote
0 answers
773 views

Asynchronous execution in BlockingQueue

I am using Java collections BlockingQueue for data processing. The current code looks like while(true){ if(queue.size() > 0) handle(queue.take()) } Is there a way (in Java or other ...
MIK's user avatar
  • 392
1 vote
0 answers
195 views

What is the difference between a bounded blocking queue and an unbounded blocking queue?

What is the difference between a bounded blocking queue and an unbounded blocking queue?
user5066233's user avatar
1 vote
0 answers
1k views

Mediacodec, decode byte packet from server and render it on surface

I have some issues with MediaCode. I have 3 components; Decoder, Downloader and Render. And Simple FragmentStreamVideo that initialize the 'SurfaceView' and the 'Downloader'. The other components ...
a23sokolov's user avatar
1 vote
1 answer
1k views

BlockingQueue like container that doesn't allow duplicates

I want a thread-safe container that blocks the caller until an item becomes available. Items will be added at a rate of 1000s per second to this container but will not be drained the same rate. ...
user1071840's user avatar
  • 3,552
1 vote
1 answer
2k views

Synchronized Queue?

I have two threads for an online game im making. One thread receives two X and Y number, and the other thread sends out the X and Y numbers to everyone logged into the server. Basically I need a queue,...
Code Doggo's user avatar
  • 2,196
0 votes
0 answers
33 views

Issue with LinkedBlockingQueue in java application

I am using LinkedBlockingQueue in my application. When the application is running the program waits at blockingqueue.take() statement. Even though after adding some objects into the queue, it is not ...
Visweswararao Atluri's user avatar
0 votes
0 answers
34 views

Is there a way to co-ordinate coroutines using on Dispatchers with wait statements across codeblocks

I have a situation with a lot of callbacks, specifically onCompleteListeners from Firebase Auth. First I am getting a Firebase Auth object using an SDK. However there is no other option but to use ...
user1743524's user avatar
0 votes
0 answers
247 views

Java data structure where elements automatically removed after specified delay for every element

Does anybody know if there is existing Java data structure where elements are automatically removed from it based on the delay for each element? In other words, each element has its own ttl. For ...
user25963's user avatar
0 votes
0 answers
60 views

Does using removeIf() on an ArrayBlockingQueue trigger a put() call from another thread?

I'm trying to remove elements manually from ArrayBlockingQueue by using the removeIf() method, using threads. And then have another thread trying to put an element into the ArrayBlockingQueue. It ...
Jia Wen Chin's user avatar
0 votes
1 answer
313 views

Problem combining Delay Queue and Executor Service

I'm trying to create an Executor Service using a DelayQueue for the blocking queue with Java 8. I created a class that implements Runnable and Delayed, and implemented the required methods: public ...
user6604739's user avatar