You could accomplish this by using a kind of semaphore, basically an Object that the threads can wait and notify on. The Object should contain two ints, and two locking Objects, one for each thread...