The problem is that notify
and notifyAll
only wake up threads holding locks on the monitor being notified. But the t1
and t2
instances are waiting on themselves and are never awoken. You can have them wait on the semaphore for this simple test or introduce a new shared object to see how it works.
Use
sem.wait();
and
sem.notifyAll();