Suppose that I've queued a work item in a ThreadPool
, but the work item blocks if there is no data to process (reading from a BlockingQueue
). If the queue is empty and there will be no more work going into the queue, then I must call the Thread.Interrupt
method if I want to interrupt the blocking task, but how does one do the same thing with a ThreadPool
?
The code might look like this:
void Run()
{
try
{
while(true)
{
blockingQueue.Dequeue();
doSomething();
}
}
finally
{
countDownLatch.Signal();
}
}
I'm aware that the best thing to do in this situation is use a regular Thread
, but I'm wondering if there is a ThreadPool
equivalent way to interrupt a work item.