为什么 wait 和 notify 方法要在同步块中调用?

Java API 强制要求这样做,如果你不这么做,你的代码会抛出

IllegalMonitorStateException 异常。还有一个原因是为了避免 wait 和 notify

之间产生竞态条件。

猜你喜欢

转载自www.cnblogs.com/programb/p/13020319.html
今日推荐