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
5
votes
2 answers

Scala Thread Pool - Invoking API's Concurrently

I have a use-case in databricks where an API call has to me made on a dataset of URL's. The dataset has around 100K records. The max allowed concurrency is 3. I did the implementation in Scala and ran in databricks notebook. Apart from the one…
Abhi
  • 6,471
  • 6
  • 40
  • 57
5
votes
3 answers

Use PriorityBlockingQueue with Comparator in ScheduledThreadPoolExecutor

First of all: I already read the following two questions and their possible solutions: ScheduledThreadPoolExecutors and custom queue Java Executors: how can I set task priority? The dilemma I'm having is that I want to use a custom BlockingQueue…
5
votes
1 answer

Why can race condition in LogWriter cause the producer to block? [Concurrency in practice]

First of all to prevent mark question as duplicate by guys who don't like read to the end I have read Producer-Consumer Logging service with Unreliable way to shutdown question. But it is not fully answer the question and answer contradicts the…
gstackoverflow
  • 36,709
  • 117
  • 359
  • 710
5
votes
1 answer

How to Block a Queue in ForkJoinPool?

I need to block threads on ForkJoinPool when its queue is full. This can be done in the standard ThreadPoolExecutor, e.g.: private static ExecutorService newFixedThreadPoolWithQueueSize(int nThreads, int queueSize) { return new…
Ivan Voroshilin
  • 5,233
  • 3
  • 32
  • 61
5
votes
1 answer

Is there a way to block on a socket and a blockingqueue in java?

Ideally I'd like to add my blocking queue to a selector so I can block reading from a socket or until an item appears on the blocking queue. Is there some higher level selector-like function that operates on disparate types like these? I could go…
stu
  • 8,461
  • 18
  • 74
  • 112
5
votes
3 answers

Does foreach remove from C# BlockingCollection?

does anyone know if, when iterating on a C# BlockingCollection<>, the elements are taken from the collection, in the same way that BlockingCollection.Take() does for example? BlockingCollection q = new…
nitbix
  • 143
  • 8
5
votes
8 answers

Does a 'blocking' queue defeat the very purpose of multi threading

The ArrayBlockingQueue will block the producer thread if the queue is full and it will block the consumer thread if the queue is empty. Does not this concept of blocking goes against the very idea of multi threading? if I have a 'main' thread and…
Victor
  • 16,609
  • 71
  • 229
  • 409
5
votes
2 answers

Gracefully ending a thread that's waiting on a blocking queue

I'm having an issue with a multi-threaded server I'm building as an academic exercise, more specifically with getting a connection to close down gracefully. Each connection is managed by a Session class. This class maintains 2 threads for the…
GordonM
  • 31,179
  • 15
  • 87
  • 129
5
votes
4 answers

Persistent Blocking Queue in Java?

TL;DR; I need to know if there's a lib with persistent blocking queue that performatic. I hava a classic producer/consumers program. They share a LinkedBlockingQueue to share the data, and I use BlockingQueue#take method in the Consumers, as I need…
Caesar Ralf
  • 2,203
  • 1
  • 18
  • 36
5
votes
2 answers

Java -BlockingQueue -- Multiple producers, single consumer

Quick clarification please I know BlockingQueues are threadsafe. Does that mean that I can pass a single reference to a blocking queue to all producers who can drop Events in willy-nilly to be consumed by a single consumer, and nothing gets…
Sheriff
  • 495
  • 4
  • 16
5
votes
2 answers

How to check duplicates are not being added to a LinkedBlockingQueue?

I am receiving messages from multiple gmail accounts using the Java mail API. The different accounts are being processed by different threads, and I am using a LinkedBlockingQueue to store the emails. However I do not want the same email repeatedly…
user1821475
  • 61
  • 1
  • 2
5
votes
3 answers

BlockingQueue vs Semaphore

If we want to implement a resource pool such as a database connection pool. Which concurrent collection will you use ? BlockingQueue or Semaphore ? For BlockingQueue, just like the producer-consumer design pattern, the producer will place all the…
peter
  • 8,333
  • 17
  • 71
  • 94
4
votes
3 answers

Blocking queue race condition?

I'm trying to implement a high performance blocking queue backed by a circular buffer on top of pthreads, semaphore.h and gcc atomic builtins. The queue needs to handle multiple simulataneous readers and writers from different threads. I've…
Andrew Tomazos
  • 66,139
  • 40
  • 186
  • 319
4
votes
1 answer

LinkedBlockingQueue and primitives

I have need for a LinkedBlockingQueue but what I am passing primitives to it. My data rates for adding to the Queue are about 4ms or 256 data points per sec. The issue that I am having is the data starts to delay immediately on start but over time…
JPM
  • 9,077
  • 13
  • 78
  • 137
4
votes
1 answer

Should I explicitly wake a thread sucking on BlockingQueue.take() for performance?

I understand that having a thread sucking for elements of a BlockingQueue using the take() method will wait for an element to be available (unless it is interrupted). I have two questions: i) Is the thread automatically woken-up as soon as an…
Jérôme Verstrynge
  • 57,710
  • 92
  • 283
  • 453