I think you're looking for a CountDownLatch - in particular, create an instance with a number of 1.
Then your operations look like this:
- hasOccurred :
latch.getCount() == 0 - wait :
latch.await() - signal :
latch.countDown()
If you want something you can reset and use repeatedly, then the CyclicBarrier may be more than what you are looking for. CountDownLatches, after they are launched, cannot be reset.
Edit: It is worth noting that CountDownLatch is more easily compiled for more work than the Event interface you were talking about. So, for example, if you are going to wait for 4 work threads, you can give each employee their own event / 1-count-latch and wait in line for the queue. However, the easiest way is to create a single CountDownLatch with a score of 4 and share it between all the workers (something that does not require any changes in the working logic at all, and this cannot be done simply with a few smaller events).
Andrzej doyle
source share