1

Why is it not possible to .join() before starting a thread? Should not be implicit that if I call join() on a thread even if not started previously should be started?

2 Answers 2

6

Because join() waits for a thread to die as the Javadoc say; it cannot die if it hasn't started yet.

I do not think it should start a thread if it is not started because the method would do two things: start a thread and wait for the thread, which is bad design.

Sign up to request clarification or add additional context in comments.

1 Comment

Yes something that does not exist yet is not worth waiting for.
2

Acorrding to javadoc

The join method allows one thread to wait for the completion of another. If t is a Thread object whose thread is currently executing,

t.join(); 

causes the current thread to pause execution until t's thread terminates. Overloads of join allow the programmer to specify a waiting period.

SO it clearly tells that if you join a thread then the current thread will wait until the termination of thread. So if a thread is not started yet how can it be terminated.

Proof By Contradiction :D

say you can join a thread t without starting. then you call

t.join(); 

now as per the behavior of join current thread will be waiting. Now say some evil thinking (!) comes to your mind and you haven't started the thread (:D). What will be happened now? Imagine this scenario and you will find your answer

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.