You can look at the use of "wait, notify, notifyAll". These work together as semaphores. The following code example is from the Java tutorial. It shows a little of how it's used with a producer/consumer combination.
public synchronized int get() {
while (available == false) {...