千万里不及你
首先synchronized修饰方法的问题对于非static方法,其作用相当于synchronized(this):synchronized void method(){// method body}// 等价于void method() { synchronized(this){ // method body }}对于static方法,其相当于synchronized(YourClass.class):class YourClass { synchronized static void method() { // method body } // 等价于 static void method() { synchronized(YourClass.class) { // method body } }}其次关于假唤醒问题,就是@spance说的。官方docde描述是:A thread can also wake up without being notified, interrupted, or timing out, a so-called spurious wakeup.官方给出的解决方案是:synchronized (obj) { while (<condition does not hold>) obj.wait(); ... // Perform action appropriate to condition }The doc