Tag: 等等

在Integer上同步时对notify()的IllegalMonitorStateException

我刚接触在Java中使用wait()和notify(),我得到一个IllegalMonitorStateException。 主要代码 public class ThreadTest { private static Integer state = 0; public static void main(String[] args) { synchronized(state) { System.out.println(“Starting thread”); Thread t = new Thread(new AnotherTest()); t.start(); synchronized(state) { state = 0; while(state == 0) { try { state.wait(1000); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } } System.out.println(“State […]