packagewait_sleep;
publicclassTestD {
publicstaticvoidmain(String[] args) {
newThread(newThread1()).start();
try {
Thread.sleep(5000);
} catch (Exceptione) {
e.printStackTrace();
}
newThread(newThread2()).start();
}
privatestaticclassThread1implementsRunnable{
@Overridepublicvoidrun(){
synchronized (TestD.class) {
System.out.println("enter thread1...");
System.out.println("thread1 is waiting...");
try {
TestD.class.wait();
} catch (Exceptione) {
e.printStackTrace();
}
System.out.println("thread1 is going on ....");
System.out.println("thread1 is over!!!");
}
}
}
privatestaticclassThread2implementsRunnable{
@Overridepublicvoidrun(){
synchronized (TestD.class) {
System.out.println("enter thread2....");
System.out.println("thread2 is sleep....");
try {
Thread.sleep(5000);
} catch (Exceptione) {
e.printStackTrace();
}
System.out.println("thread2 is going on....");
System.out.println("thread2 is over!!!");
TestD.class.notify();
}
}
}
}