I'm using a java.util.concurrent.CountDownLatch
object (latch
) to control a set of Runnable
s which get executed via a thread pool (which could also be executing other Runnable
s).
In certain (and desirable) instances, the main thread is interrupted whilst waiting in latch.await()
. and I need to catch and deal with java.lang.InterruptedException
.
What I want to do is to interrupt all the threads that are currently running in the thread pool on behalf of this particular latch, and cancel any Runnable
s that are queued to run in that pool. To re-iterate: I can't simply interrupt everything in the pool and cancel all pending queued Runnable
s as it used by other processes.
I presume this is a standard construct, but can't find it.
Therefore before I embark on implementing this from scratch, I would be delighted to know if Java has a canned object or a standard approach for doing this.