开发者

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜