XException in thread "main" java.lang.IllegalMonitorStateException
at java.lang.Object.wait(Native Method)
at MainClass.a(MainClass.java:10)
at MainClass.main(MainClass.java:3)
The code does not acquire a lock on t before calling t.wait() , so it throws an IllegalMonitorStateException .