Waits for this thread to die.
As you said, if you start a thread before joining, the thread may be dead so there is nothing to join. But I dont see that in your example.
Can we join() main thread from AAA's run()?
1- Main waits for theThread to die before it(main) could proceed. Right?
No, misunderstanding. I meant the code in the run method of AAA is so short, that the AAA thread has already started, run and died, before main reaches the line with the join().
2- You mean, the code after theThread.start() is very short so before run could execute main dies.
I do not have an MD in psychiatry, but I guess you are suffering from a desease that is called THREAD (Traumatic Hypermania Related Encephalitis Associated Dissociation)
Am I gone mad?
One thread may call join() on another thread to wait for
the second thread to complete before proceeding. If a thread
calls t.join() on another thread t,then the calling thread
is suspended until the target thread t finishes (when
t.isAlive() is false.
The correct explanation of the code would be (as I think), main thread (Burkhard, I think I hope you get me what main I am talking about) calls
the join() on the theThread and theThread is alive so main thread joins to the theThread; and Chandra Bhatt is happy with the output.
theThread which is not alive at that moment so according to Bruce, main wont join it.
main thread starts as soon as you enter the main() method. So, we need not test whether it's alive or not. We don't say main().start right?
However, if we are joining some other thread, as you said, it will be good to test whether its alive or not.