public class Thread16 {
private static final Object LOCK = new Object();
public static void main(String[] args) {
for(int i = 0; i < 10; i++) {
new Thread("thread"+i) {
@Override
public void run() {
synchronized(LOCK) {
try {
System.out.println(Thread.currentThread().getName() + " wait ");
LOCK.wait();
System.out.println(Thread.currentThread().getName() + " active ");
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}.start();
}
try {
Thread.sleep(3*1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
for(int i = 0; i < 10; i++) {
synchronized(LOCK) {
LOCK.notify();
}
}
}
}
thread0 wait
thread2 wait
thread1 wait
thread3 wait
thread4 wait
thread5 wait
thread6 wait
thread8 wait
thread7 wait
thread9 wait
thread0 active
thread5 active
thread4 active
thread3 active
thread1 active
thread2 active
thread9 active
thread7 active
thread8 active
thread6 active
public class Thread16 { private static final Object LOCK = new Object(); public static void main(String[] args) { for(int i = 0; i < 10; i++) { new Thread("thread"+i) { @Override ...