Conceptual Java Concurrency Question

If I have a class whose run () method falls asleep for 1000 ms, then type β€œThread”. And I start this thread from my main program, and then my main program immediately sleeps for 2000 ms, and then prints the "Main stream".

Is Thread Printing Guaranteed Before the Main Thread?

+6
java
source share
1 answer

Nope. Conceptually, it is possible that the system you are working on will be so busy that the new thread does not even get a chance to start something before the main thread has time to sleep and print the "Main Topic". In fact, which is very unlikely, of course, but fundamentally sleep not a coordination primitive.

+16
source share

All Articles