Is a notify signalled on thread finish? Why does this code sample work?
问题 I am looking in some puzzles for threads and I can't figure out why the following consistently prints 999999 : class Job extends Thread { private Integer number = 0; public void run() { for (int i = 1; i < 1000000; i++) { number++; } } public Integer getNumber() { return number; } } public class Test { public static void main(String[] args) throws InterruptedException { Job thread = new Job(); thread.start(); synchronized (thread) { thread.wait(); } System.out.println(thread.getNumber()); } }