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

Is adding tasks to BlockingQueue of ThreadPoolExecutor advisable?

The JavaDoc for ThreadPoolExecutor is unclear on whether it is acceptable to add tasks directly to the BlockingQueue backing the executor. The docs say calling executor.getQueue() is "intended primarily for debugging and monitoring". I'm…
user23987
20
votes
3 answers

Thread-safety of BlockingQueue's drainTo() method

Documentation of BlockingQueue says bulk operations are not thread-safe, though it doesn't explicitly mention the method drainTo(). BlockingQueue implementations are thread-safe. All queuing methods achieve their effects atomically using …
Shashikant Kore
  • 4,952
  • 3
  • 31
  • 40
16
votes
3 answers

Queue Full, On depth of the Blocking Queue, clarification needed

When populating the queue from the contents of the file, depth does not seem to ever increase, as elements are not added in this implementation. BlockingQueue q = new SynchronousQueue(); ... fstream = new…
James Raitsev
  • 92,517
  • 154
  • 335
  • 470
14
votes
4 answers

implement-your-own blocking queue in java

I know this question has been asked and answered many times before, but I just couldn't figure out a trick on the examples found around internet, like this or that one. Both of these solutions check for emptiness of the blocking queue's…
13
votes
3 answers

Being asynchronously notified of a BlockingQueue having an item available

I need an Object to be asynchronously notified when some BlockingQueue has got an item to give. I've searched both Javadoc and the web for a pre-made solution, then I ended up with a (maybe naive) solution of mine, here it is: interface…
gd1
  • 11,300
  • 7
  • 49
  • 88
13
votes
2 answers

Re-sizeable Java BlockingQueue

So I am using a fixed sized BlockingQueue [ArrayBlockingQueue] in a producer/consumer type application, but I want the user to be able to change the queue size on the fly. Problem is there is not a BlockingQueue implementation that allows changing…
Gandalf
  • 9,648
  • 8
  • 53
  • 88
13
votes
3 answers

Java (Android) multi-threading process

I am working on application (Matt's traceroute windows version http://winmtr.net/) which creates multi threads each thread has its own process (which execute ping command). ThreadPoolExecutor shutdown all threads after some time( e.g.10…
13
votes
4 answers

ThreadPoolExecutor policy

I'm trying to use a ThreadPoolExecutor to schedule tasks, but running into some problems with its policies. Here's its stated behavior: If fewer than corePoolSize threads are running, the Executor always prefers adding a new thread rather than…
Joe K
  • 245
  • 3
  • 7
11
votes
1 answer

Android Looper vs BlockingQueue?

Can anyone explain why someone should use the Android Looper feature to create a "pipeline thread" instead of making a normal thread that pulls tasks from a BlockingQueue? On the surface, it seems like two ways to do the same thing.
jfritz42
  • 5,913
  • 5
  • 50
  • 66
11
votes
3 answers

producer/consumer work queues

I'm wrestling with the best way to implement my processing pipeline. My producers feed work to a BlockingQueue. On the consumer side, I poll the queue, wrap what I get in a Runnable task, and submit it to an ExecutorService. while…
11
votes
3 answers

Wait until a BlockingCollection queue is cleared by a background thread, with a timeout if it takes too long?

In C#, I'm wondering if it's possible to wait until a BlockingCollection is cleared by a background thread, with a timeout if it takes too long. The temporary code that I have at the moment strikes me as somewhat inelegant (since when is it good…
Contango
  • 76,540
  • 58
  • 260
  • 305
11
votes
7 answers

what's wrong with my sensor monitoring technique?

(please read UPDATE 3 at the end)I'm developing an app that continually works with the sensors of device, works with Accelerometer and Magnetic sensors to retrieve the orientation of device(the purpose is mentioned here). in other words, my app…
Soheil
  • 1,676
  • 7
  • 34
  • 65
11
votes
4 answers

ArrayBlockingQueue uses a single lock for insertion and removal but LinkedBlockingQueue uses 2 separate locks

I was going through the source code of ArrayBlockingQueue and LinkedBlockingQueue. LinkedBlockingQueue has a putLock and a takeLock for insertion and removal respectively but ArrayBlockingQueue uses only 1 lock. I believe LinkedBlockingQueue was…
user1168577
  • 1,863
  • 11
  • 14
10
votes
2 answers

PDF file download using BlockingQueue

I'm trying to download a pdf file using URLConnection. Here's how I setup the connection object. URL serverUrl = new URL(url); urlConnection = (HttpURLConnection)…
Renjith
  • 3,457
  • 5
  • 46
  • 67
9
votes
1 answer

What is the advantage of forking a stream over just using multiple streams?

I am reading java 8 in action and the author references this link: http://mail.openjdk.java.net/pipermail/lambda-dev/2013-November/011516.html and writes his own stream forker that looks like this: import java.util.*; import…
1
2
3
30 31