I sometimes write code like:
Method 1:
synchronized (someMonitor) {
newInfo = true;
someMonitor.notifyAll();
}
Method 2:
synchronized (someMonitor) {
while (!newInfo) {
someMonitor.wait();
}
newInfo = false;
}
I imagine there's a higher-level concurrency object in the API to handle this. It should work like:
Method 1:
ensureFlagRaised();
Method 2:
blockUntilFlagRaisedThenLowerFlag();
I could use a BlockingQueue with capacity 1 to call the non-blocking offer(dummyElement) and the blocking take(). But this seems like an abuse of that class.
Any cleaner solutions?