I created this silly program to play with wait()
public class WaitTest {
public static void main(String [] args) {
System.out.print("1 ");
synchronized(args){
System.out.print("2 ");
try {
args.wait();
args.notifyAll();
}
catch(InterruptedException e){ System.out.print("exception caught");}
System.out.print("3 ");
}
}
}
On my machine, the code never gets to print 3, unless I write wait(100)
or another number of milliseconds. Why is this?