我有一个对象在线程A上调用wait()
,同时另一个对象在线程B上执行一些工作,然后调用线程A的对象的notify()
。线程A然后执行一些后处理。
我的问题非常简单:
synchronized(this)
{
while(!flag)
{
try
{
wait();
getLogger().info("No longer waiting");
}
catch (InterruptedException ie)
{
getLogger().info("Wait threw InterruptedException");
}
}
}
在信息提示中,将“Wait threw InterruptedException”更改为“No longer waiting”。
我感到困惑,因为这个(http://download.oracle.com/javase/1.5.0/docs/api/java/lang/Object.html#wait()):
抛出:
InterruptedException - 如果另一个线程在当前线程等待通知时中断了当前线程。当抛出此异常时,当前线程的中断状态被清除。
为什么我会得到奇怪的行为?
谢谢。
notify
并不算作中断。 - sje397