I'm using CountDownLatch
es to wait for a specific even but I need to be able to abort its await()
method and throw an exception right away.
It's not nearly a challenge but I'm wondering if Java has something out of the box to do that for me because it sounds like a reasonable option to have.
Example:
SpecialCountDownLatch latch = new SpecialCountDownLatch();
Thread-1:
latch.await();
Thread-2:
latch.interrupt(); // Forces latch.await() at Thread-1 to throw an exception