public class Test {
public static void main(String[] args)
{
new Test();
System.out.print("Done");
}
public Test()
{
Test t1 = this;
Test t2 = this;
synchronized(t1)
{
try
{
t2.wait();
}
catch(InterruptedException e)
{
System.out.print("!");
}
catch(Exception e)
{
System.out.print("!!");
}
finally
{
System.out.print("@@");
}
}
System.out.print("!!!");
}}
请问以上代码运行后,输出结果是什么?
谢谢了~!
public static void main(String[] args)
{
new Test();
System.out.print("Done");
}
public Test()
{
Test t1 = this;
Test t2 = this;
synchronized(t1)
{
try
{
t2.wait();
}
catch(InterruptedException e)
{
System.out.print("!");
}
catch(Exception e)
{
System.out.print("!!");
}
finally
{
System.out.print("@@");
}
}
System.out.print("!!!");
}}
请问以上代码运行后,输出结果是什么?
谢谢了~!
public final void wait() throws InterruptedException {
wait(0);
}
学习
Test t2 = this;
这两句到底要作什么啊?
finally
{
System.out.print("@@");
}
}System.out.print("!!!");
}
这些都需要等t2.wait()执行完后才会继续。而main函数里面的System.out.print("Done");则更不会执行,因为new Test();这个动作还停在t2.wait()呢,所以,什么输出结果都不会有!