SCJP6
Leandro Coutinho wrote:I didn't start the Thread part yet, but ...
I don't think sleep has something to do to switch context. It just makes the thread stop for a certain time.
After the join, you can assure that "post" will be the last to be printed.
SCJP6
Ryan Beckett wrote:You don't have to worry about the lock here. If main happens to execute first (which is unpredictable), "pre" is printed, then your guaranteed that "post" won't print until after "in" because of the call to join.
Thread.join() says I will wait to execute until the thread I'm calling join on is finished executing.
SCJP6
Henry Wong wrote:
This question has come up a few times in this forum -- it may be a good idea to search for old discussions.
The jist of the previous discussions were... Yes, D is theoretically possible -- as schedulling is not defined. However, the chances of having a JVM that is so broken, that it could not schedule the main thread to run, within 2 seconds, and no other threads in the program, is highly improbable. Common sense says D can't be right.
Henry
SCJP6
Henry Wong wrote:
This question has come up a few times in this forum -- it may be a good idea to search for old discussions.
The jist of the previous discussions were... Yes, D is theoretically possible -- as schedulling is not defined. However, the chances of having a JVM that is so broken, that it could not schedule the main thread to run, within 2 seconds, and no other threads in the program, is highly improbable. Common sense says D can't be right.
Henry
SCJP6
Destiny's powerful hand has made the bed of my future. And this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
|