Is the output possible:Thread-0 runs before main THread-0
A
main
B
i had ran this code 10 times,still the same output
OCPJP 6.0 93%
OCPJWCD 5.0 98%
Lester Burnham
Rancher
Joined: Oct 14, 2008
Posts: 1337
posted
0
Not sure what you mean by "Is the output possible: Thread-0 runs before main" - you're observing it, so obviously it's possible.
Since the "B" thread is put to sleep, the JVM will choose some other thread to run, and the "A" thread is the only other user thread in existence - so this behavior is to be expected.
Thread-0 cannot print anything before main method because of the while loop in the GotIT method which will only end when the main method sets x to 1...