【发布时间】:2013-10-10 09:43:17
【问题描述】:
public class ThreadConfusion
{
public static void main(String[] args)
{
System.out.print("1 ");
synchronized (args)
{
System.out.println(" 2");
try
{
args.wait();
}
catch (InterruptedException e)
{
System.out.println("exception");
}
}
System.out.println("3 ");
} //end of the main method
} // end of the class
输出
1 2
为什么输出是 1 2 而不是 1 2 3。那边到底发生了什么?
【问题讨论】:
-
你为什么叫 wait() ?它在等你调用 notify()
-
更重要的是:您希望给谁打电话
args.notify()?这里没有其他线程...
标签: java object locking wait synchronized