死锁用例
public class DeadLock {
private static String A="A";
private static String B="B";
public static void main(String[] args) {
Thread threadA=new Thread(new Runnable() {
@Override
public void run() {
synchronized(A){
System.out.println(A);
try {
Thread.currentThread().sleep(2000);
} catch (InterruptedException e) {
e.printStackTrace();
}
synchronized(B) {
System.out.println(B);
}
}
}
});
Thread threadB=new Thread(new Runnable() {
public void run() {
synchronized(B) {
synchronized(A) {
System.out.println("AA");
}
}
}
});
threadA.start();
threadB.start();
}
}