我在线程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");
}
}
}
Run Code Online (Sandbox Code Playgroud)
导致信息消息"不再等待"而不是"等待中断异常".
我很困惑,因为这个(http://download.oracle.com/javase/1.5.0/docs/api/java/lang/Object.html#wait()):
抛出:
InterruptedException - 如果另一个线程在当前线程等待通知之前或当前线程中断当前线程.抛出此异常时,将清除当前线程的中断状态.
为什么我会出现奇怪的行为?
谢谢.