Hi ranchers This question is from Devaka ExamLab 5.0 , nr 72
answer : "ABC" Davaka has explained, that we synchronized on two different objects.
He said :
"Therefore the new thread can freely enter to the synchronized
context of the run() method, while the main thread is sleeping"
I don't agree with his last sentence and further answer.
what will be answer when Line 1 will be Thread.sleep(10) ?
or Thread.sleep(1) ...
or Thread.sleep(0) ?
have we still "ABC" or already "XYZ"?
In my opinion, we can't say for sure that one thread is running during other thread is sleeping.
Back to the example:
After Line 1, thread scheduler may choose some different thread to running state, neither of above. And
after 1000 miliseconds will go back, and will choose immediately main thread to running. In that case,
our answer will be "XYZ".
So, I think we shouldn't rely on Thread.sleep() when we talk about flow, but rather only on sure
things like join, objects lock & synchronized blocks/methods or wait().
What is your opinion ? I think,in regard to the above, correct answer should be "Result is unpredictable".