In a multi-threaded java program, what happens if a thread object T has been instantiated, and then has T.join() called before the thread has started? Assume that some other thread could call T.start() at any time after T has been instantiated, either before or after another thread calls T.join().
I’m asking because I think I have a problem where T.join() has been called before T.start(), and the thread calling T.join() hangs.
Yes, I know I have some design problems that, if fixed, could make this a non-issue. However, I would like to know the specifics of the join() behavior, because the only thing the Java API docs say is “Waits for this thread to die.”
It will just return. See code below – isAlive() will be false before the thread starts, so nothing will happen.
The code snippet is © Copyright Oracle 2006 and/or its affiliates, and can be found here. Licensed under Java Research License.