[concurrency-interest] Queue with interrupt

Jochen Theodorou blackdrag at gmx.org
Wed May 17 05:25:43 EDT 2017

On 17.05.2017 08:31, David Holmes wrote:
> Hi Jochen,
> How are you "waiting for tasks"? As you note a Queue has no notion of
> blocking on empty. Using a BlockingQueue you can either interrupt the
> worker thread or send a sentinel task that simply indicates "do the
> other processing now". Of course I can't tell you know whether the
> worker is waiting or working - you can't arbitrarily "interrupt" the
> execution of a task.

I think maybe it is better to show some code...

addTasks and interrupt are called from a different thread than 
executeTasks. executeTasks is responsible for one iteration of task 
executions, not a continuously blocking worker.

I do not want to interrupt task execution of course, only the waiting.

So your suggestion is to add a sentinel task... I guess that works, as 
long as I can add the task before already existing tasks, that may be 
still in the queue, so that it can interrupt between task executions ( 
not during of course)

bye Jochen

More information about the Concurrency-interest mailing list