David Wall writes:
 > Have a method, such as stop(), that sets a boolean, and in the thread that's
 > running, have it loop testing if the boolean has been set by stop() or not,
 > and if so, then exit itself.
 > 
 > Stopping a thread otherwise is problematic because it is not clear where it
 > was when it was stopped (it's an ugly stop).  I've heard it mentioned that
 > it can also leave some threads in a bad a state, but that seems more like a
 > bug with the JVM not doing clean-up to me.   But stopping nicely is always
 > best...

This, in effect, is that the interrupt mechanism does.  It sets an interrupted
flag in the thread that user code can watch for, and I think it breaks you out
of Thread.sleep or other thread related operations.  User code can loop looking
for the thread to be interrupted, and gracefully exit when it has been.

Steve


Reply via email to