Conceptual Question About Java Concurrency
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.
精彩评论