我需要在這裏解釋。線程正在等待另一個線程
public static void main(String[] args) {
FirstThread obj = new FirstThread();
for (int i = 1; i <= 10; i++) {
new WaiterThread(obj).start();
}
obj.start();
}
public class FirstThread extends Thread {
@Override
public void run() {
// Do something
}
}
public class WaiterThread extends Thread {
Object obj;
WaiterThread(Object obj) {
this.obj = obj;
}
@Override
public void run() {
synchronized (obj) {
obj.wait();
}
}
}
10個線程爲WaiterThread創建並正在等待的單個FirstThread對象。之後FirstThread終止,所有WaiterThread重操舊業沒有obj.notify()或obj.notifyAll()被稱爲任何地方。
這是否意味着WaiterThread s已停止等待FirstThread因爲它被終止?
人們會懷疑我們坐在同一個房間:) –
很高興見到你:-) –
當然,同樣:) –