SCJP2. Please Indent your code using UBB Code
Dave
SCJP2. Please Indent your code using UBB Code
Tests if this thread is alive. A thread is alive if it has been started and has not yet died.
Really? I haven't noticed it. :-)
Any comments more interesting?
dan moore, infomatiq ltd.<br />email dan@infomatiq.co.uk<br /><a href="http://www.infomatiq.co.uk" target="_blank" rel="nofollow">http://www.infomatiq.co.uk</a>
toStop could well never acquire the lock .
the javadocs for isAlive state that the method isALive tests if this thread is alive. A thread is alive if it has been started and has not yet died.
but the relationship between start() and run() is asynchronous - a thread can be started without it having entered run() yet.
sarcasm is probably not the best way to stop a discussion thread - perhaps that should be deprecated, too.
SCJP2. Please Indent your code using UBB Code
dan moore, infomatiq ltd.<br />email dan@infomatiq.co.uk<br /><a href="http://www.infomatiq.co.uk" target="_blank" rel="nofollow">http://www.infomatiq.co.uk</a>
my first guess was that the VM work required to enter the toStop synchronization block is greater (more time consuming) than work to enter the test block.
i think the answer is that it is not really a race between the toStop and test threads (as it looked at first to me), but a race between the main thread and the toStop thread.
it shows that it is unlikely that toStop will actually start running, acquire lock and print out its statement before the main thread that started it manages to call toStop.stop(). in fact, quite probable that the toStop thread is stopped before either toStop or test actually runs.
does that make sense?
SCJP2. Please Indent your code using UBB Code
Consider Paul's rocket mass heater. |