没有哪一本书写得比javadoc好 This method should only be called by a thread that is the owner of this object's monitor. A thread becomes the owner of the object's monitor in one of three ways: By executing a synchronized instance method of that object. By executing the body of a synchronized statement that synchronizes on the object. For objects of type Class, by executing a synchronized static method of that class. wait()在这几个条件下能用. --是如果在没有使用多线程的程序里,如最简单的helloworld,调用了wait,这样会产生什么样的效果,使得主线程等待吗,那么又由那个对象来激活它呢,或者出于无知,调用了notfiy会有什么结果? 按照以上条件,会抛出异常吧!
建议楼主你仔细阅读<<Thinking In java 2>>第14章节
This method should only be called by a thread that is the owner of this object's monitor. A thread becomes the owner of the object's monitor in one of three ways: By executing a synchronized instance method of that object.
By executing the body of a synchronized statement that synchronizes on the object.
For objects of type Class, by executing a synchronized static method of that class.
wait()在这几个条件下能用.
--是如果在没有使用多线程的程序里,如最简单的helloworld,调用了wait,这样会产生什么样的效果,使得主线程等待吗,那么又由那个对象来激活它呢,或者出于无知,调用了notfiy会有什么结果?
按照以上条件,会抛出异常吧!