As the question suggests , I want to know the similarity between the sleep and join methods on the thread. I have gone through many questions that describe the difference betwee
NO NO NO
sleep
and join
are completely different.
join
will wait for the specified Thread
to finish (either normally or abnormally) or until the time expires.
sleep
will simply stop the current thread for the specified time.
They are completely different. One explicitly waits for another Thread
and wakes the instant that that Thread
ends. sleep
just stops execution.
If you can guarantee than newThread
will take longer then 10,000ms
to to complete then they become equivalent, but this is a degenerate case.
If you want to wait for another Thread
to complete use join
.
If you want your current Thread
to stop what it's doing and sleep for a while use sleep
.