If I I have a class whose run() method sleeps for 1000 ms and then print "Thread". And I start this thread from my main program, then have my main program immediately sleep for 2000 ms, and then print "Main Thread".
Is it guaranteed that Thread will be printed before Main Thread?
Nope. Conceptually, it's possible that the system you're running on will be so busy that the new thread doesn't even get a chance to run anything before the main thread has had a chance to sleep and print "Main Thread". In reality that's very unlikely, of course, but fundamentally sleep
is not a coordination primitive.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With