[concurrency-interest] Queue with interrupt
davidcholmes at aapt.net.au
Wed May 17 02:31:46 EDT 2017
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.
> -----Original Message-----
> From: Concurrency-interest [mailto:concurrency-interest-bounces at cs.oswego.edu] On Behalf Of Jochen Theodorou
> Sent: Wednesday, May 17, 2017 4:15 PM
> To: concurrency-interest at cs.oswego.edu
> Subject: [concurrency-interest] Queue with interrupt
> Hi all,
> yesterday I was looking for a certain behaviour, but was not finding one and I am wondering if I did overlook something.
> I have 1 Thread - lets call it worker, that needs to execute a series of tasks. If there are no tasks this thread has to wait for a maximum
> of 5 seconds. After this time I have to send something like an update from this thread (has to be the same thread) to later continue on
> waiting for tasks or handle the new ones. At this point I will not car if processing the tasks takes longer than 5 seconds. And now the
> specialty: A second thread must be able to send an interrupt to the worker thread, which than has to stop waiting for new jobs and
> send the update right away, to then get back to waiting for jobs. I cannot send the update from the interrupting thread.
> Now I was expecting to find something in a Queue implementation, but while I did find a way to wait for new elements, I did not find a
> wait to interrupt that waiting. We solved this by using a BlockingQueue, plus some signaling, but it really does not feel right to me.
> Any idea how to do this better?
> bye Jochen
> Concurrency-interest mailing list
> Concurrency-interest at cs.oswego.edu
More information about the Concurrency-interest