Edd*_*ion 4 java concurrency notify wait
为什么没有线程等待notify()?线程启动然后进入等待池,但是在那之后它继续执行.
public class JavaApplication2 {
public static void main(String [] args) {
ThreadB b = new ThreadB();
synchronized(b) {
b.start();
try {
System.out.println("1");
b.wait();
} catch (InterruptedException e) {}
System.out.println("Total is: " + b.total);
}
}
}
class ThreadB extends Thread {
int total;
@Override
public void run() {
synchronized(this) {
total += 1;
//notify();
}
}
}
Run Code Online (Sandbox Code Playgroud)