?? deadlock.java
字號(hào):
class A
{
synchronized void foo(B b)
{
String name=Thread.currentThread().getName();
System.out.println(name+"entered A.foo");
try
{
Thread.sleep(1000);
}
catch(Exception e)
{
System.out.println("A Interrupted");
}
System.out.println(name+"trying to call B.last()");
b.last();
}
synchronized void last()
{
System.out.println("Inside A.last");
}
}
class B
{
synchronized void bar(A a)
{
String name=Thread.currentThread().getName();
System.out.println(name+"entered B.last");
try
{
Thread.sleep(1000);
}
catch(Exception e)
{
System.out.println("B Interrupted");
}
System.out.println(name+"trying to call A.last()");
a.last();
}
synchronized void last()
{
System.out.println("Inside A.last");
}
}
public class DeadLock implements Runnable
{
A a=new A();
B b=new B();
DeadLock()
{
Thread.currentThread().setName("main thread");
Thread t=new Thread(this,"RacingThread");
t.start();
a.foo(b);
System.out.println("Back in main thread");
}
public void run()
{
b.bar(a);
System.out.println("Back in other thread");
}
public static void main(String[] args)
{
new DeadLock();
}
}
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -