Hello, I am presently studying
Thread's join method. As per the docs:
There are 2 other constructors as well, allowing thread to specify the time to wait, before it can die.
What's the difference between the timeout specified in join and sleep method? In both cases, the thread waits for it to get over and I guess in both cases, the waiting thread can interrupt the blocking thread to get inside the method.
As an example, consider following code:
If I specify the timeout as 40000 in either sleep or join method, thread2 has to wait, before it can print out the
String.
Moreover, I don't understand the point where docs say, that join lets other threads to wait
until the blocking thread's timeout expires, or it dies. Can you let me know any scenario or example, where the join's timeout period is very high, but the thread actually finishes its work before that, and dies before the timeout actually expires. If not, I guess this is pretty much the same as sleep.
Thanks.