package threadimp;
public class MySync {
public static void main(String[] args) {
final MySync sync1 = new MySync();
final MySync sync2 = new MySync();
new Thread("thread1") {
@Override
public void run() {
synchronized (sync1) {
System.out.println(this.getName() + " start");
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println(this.getName() + " wake up");
}
}
}.start();
new Thread("thread2") {
@Override
public void run() {
synchronized (sync1) {
System.out.println(this.getName() + " start");
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println(this.getName() + " wake up");
}
}
}.start();
}
}
网友评论