`
newslxw
  • 浏览: 207772 次
  • 性别: Icon_minigender_1
  • 来自: 广州
社区版块
存档分类
最新评论

wait和notify使用方法

阅读更多
原则是:
调用wait的对象必须是synchronized中的对象,而调用notify/notifyAll的对象也必须是synchronized中的对象
public static Thread thread;
synchronized(thread)
{
  thread.wait();
//不能是其他对象wait,必须是synchronized中指定的对象
}

synchronized(thread)
{
  thread.notifyAll();

}
//不能是其他对象wait,必须是synchronized中指定的对象

参考:
[url]
http://www.cnblogs.com/rongxh7/archive/2010/04/11/1709333.html
[/url]
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics