一个关于wait方法的难题?

Sylix 2004-07-09 01:42:58
JAVA中对wait方法超时语意不准确的问题?
如wait(10000), 即等待10秒,
但实际可能会只等待1秒还不到,
有什么方法解决这个问题?
...全文
150 2 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
dropship 2004-07-09
  • 打赏
  • 举报
回复
如果没有其他的线程nofify或者notifyAll的话,程序是应该等待10秒的。
具体的请看sun的说明:
Some other thread invokes the notify method for this object and thread T happens to be arbitrarily chosen as the thread to be awakened.
Some other thread invokes the notifyAll method for this object.
Some other thread interrupts thread T.
The specified amount of real time has elapsed, more or less. If timeout is zero, however, then real time is not taken into consideration and the thread simply waits until notified.
ecaol 2004-07-09
  • 打赏
  • 举报
回复
UP

62,634

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧