who and when notify the thread.wait() when thread.join() is called?

As for jdk7 for linux, you can get the answer from the source code of openjdk. /jdk7/hotspot/src/os/linux/vm/os_linux.cpp int ret = pthread_create(&tid, &attr, (void* (*)(void*)) java_start, thread); static void *java_start(Thread *thread) { … thread->run(); return 0; } and when start thread in java, the thread will be instanceof JavaThread. /jdk7/hotspot/src/share/vm/runtime/thread.cpp void JavaThread::run() { … thread_main_inner(); } … Read more

running 3 threads in sequence java

Convert those IF statements to WHILE statements to get the desired behavior: if (notifyAllExample.status != 2){ notifyAllExample.wait(); } to while (notifyAllExample.status != 2){ notifyAllExample.wait(); } This will ensure that if a thread is notified, it won’t go out of the while loop until the status value is what it expects. Also, mark status as volatile … Read more