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

ExecutorService with a fixed sized thread pool - how to block any more tasks being added until the pool size has space

My current implementation counts how many tasks are added to the pool and decrements when the complete their task. I then tell the main code to repeat + sleep until the active tasks drop below the thread pool size before I add another task. I feel…
2
votes
1 answer

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 (fast userspace mutex) and it's a Linux construct to…
Andy
  • 183
  • 1
  • 1
  • 7
2
votes
2 answers

Why ArrayBlockingQueue hasn't been blocked when the queue is full

I have a simple test for ArrayBlockingQueue as below: public class TestQueue { static class Producer implements Runnable { private ArrayBlockingQueue queue; private int index; public…
gesanri
  • 237
  • 1
  • 3
  • 10
2
votes
2 answers

How to avoid starvation in multi producer and consumer?

Consider here 2 producer threads and one consumer thread. Suppose queue is full. Two producer thread goes to wait state because queue is full. Consumer thread takes element from queue and notifyAll so one of the producer thread adds element and…
2
votes
1 answer

LinkedBlockingQueue put and take functional implementation

I was going through internal implementation of LinkedBlockingQueue put(E e) and take() function. public E take() throws InterruptedException { E x; int c = -1; final AtomicInteger count = this.count; final ReentrantLock takeLock =…
Amit Goel
  • 157
  • 1
  • 6
2
votes
0 answers

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 something like…
Orest
  • 6,548
  • 10
  • 54
  • 84
2
votes
1 answer

Java - Single thread executor

I have blocking queue with multiple producers and single consumer (which enough for post processing of items). Producers starts by schedule which send tasks to executor pool and then tasks adds by workers to queue. My question about how to start…
Sonique
  • 6,670
  • 6
  • 41
  • 60
2
votes
1 answer

WorkerThread: Wait for processing done (BlockingQueue)

im an building a multithreaded application, using WorkerThreads which process Tasks from BlockingQueues. The worker looks as follws (as an abstract class. subclasses implement processItem()). abstract class WorkerThread extends Thread { …
markus
  • 511
  • 1
  • 4
  • 15
2
votes
3 answers

Custom Array Blocking Queue

I am trying to implement Blocking Queue functionality but Thread goes in wait state. Not able to figure out what may be going wrong. I tried some of the implementations online, but none are working. Maybe my executors code is wrong. But if I replace…
garg10may
  • 5,794
  • 11
  • 50
  • 91
2
votes
1 answer

What is the use of queueSizeRejectionThreshold in Hystrix when I already have max.Queue.poolSize?

Why we need queueSizeRejectionThreshold in Hystrix apart from maxQueueSize? By definition, queueSizeRejectionThreshold <= maxQueueSize. But I am not getting why not to reject thread when maxQueueSize becomes full, why to introduce the term…
Anuj Vishwakarma
  • 812
  • 8
  • 22
2
votes
2 answers

How to manage threads in Spring TaskExecutor framework

I have a BlockingQueue of Runnable - I can simply execute all tasks using one of TaskExecutor implementations, and all will be run in parallel. However some Runnable depends on others, it means they need to wait when Runnable finish, then they can…
Marx
  • 804
  • 10
  • 23
2
votes
0 answers

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 producer code is working fine but my consumer…
Piyush
  • 388
  • 1
  • 6
  • 21
2
votes
1 answer

Is there a method to make ros::spinOnce() call a specific number of callbacks from the callback queue?

I am writing a program in ROS that should perform certain computations after each callback function. My callback function basically subscribes to a topic and sets the value of a variable which is used to perform a specific computation. The topic…
Telepresence
  • 619
  • 2
  • 7
  • 22
2
votes
2 answers

Evict object from ArrayBlockingQueue if full

I am using an ArrayBlockingQueue but sometimes it gets to full and prevents other objects to be added to it. What I would like to do is to remove the oldest object in the queue before adding another one when the ArrayBlockingQueue gets full. I need…
user1982350
  • 2,441
  • 2
  • 14
  • 11
2
votes
1 answer

ArrayBlockingQueue: Why global variables are not accessed directly?

In the ArrayBlockingQueue Implementation, Why the global variables are not accessed directly ? public class ArrayBlockingQueue extends AbstractQueue implements BlockingQueue, java.io.Serializable { /** The queued items */ …
Kamal Chandraprakash
  • 1,872
  • 18
  • 28