class Test {
public synchronized void w() {
System
try {
wait(
} catch (InterruptedException e) {
// TODO Auto
e
}
System
notify()
}
public synchronized void n() {
System
try {
wait()
} catch (InterruptedException e) {
// TODO Auto
e
}
System
}
}
class ThreadA
Test t = null;
public ThreadA
this
}
public void run() {
t
}
}
class ThreadA
Test t = null;
public ThreadA
this
}
public void run() {
t
}
}
public class ThreadTest
public static void main(String[] args) {
Test t = new Test()
ThreadA
ThreadA
a
a
}
}
結果
開始輸出
go into w
go into n
過
get out w
get out n
From:http://tw.wingwit.com/Article/program/Java/gj/201311/27364.html