62,614
社区成员
发帖
与我相关
我的任务
分享
public class Test {
private static String s1 = "";
private static String s2 = "";
public static void main(String[] args) {
Thread t1 = new Thread() {
public void run() {
synchronized (s1) {
try {
Thread.sleep(2000);
} catch (InterruptedException e) {
e.printStackTrace();
}
synchronized (s2) {
System.out.println("............");
}
}
}
};
Thread t2 = new Thread() {
public void run() {
synchronized (s2) {
try {
Thread.sleep(2000);
} catch (InterruptedException e) {
e.printStackTrace();
}
synchronized (s1) {
System.out.println("............");
}
}
}
};
t1.start();
t2.start();
}
}