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
- Re: Deprecated `Thread.stop()' in forthcoming J... Daniel W. Dulitz x108
- Re: Deprecated `Thread.stop()' in forthcoming JDK 1.... David Young
- RE: Deprecated `Thread.stop()' in forthcoming JDK 1.... Harold G. Andrews II
- Re: Deprecated `Thread.stop()' in forthcoming JDK 1.... Michael Sinz
- Re: Deprecated `Thread.stop()' in forthcoming J... peter . pilgrim
- Re: Deprecated `Thread.stop()' in forthcomi... Pavel Tolkachev
- Re: Deprecated `Thread.stop()' in forth... peter . pilgrim
- Re: Deprecated `Thread.stop()' in f... peter . pilgrim
- Re: Deprecated `Thread.stop()' in forthcoming JDK 1.... David Wall
- Re: Deprecated `Thread.stop()' in forthcoming J... Nelson Minar
- Re: Deprecated `Thread.stop()' in forthcoming J... Steve Byrne
- Re: Deprecated `Thread.stop()' in forthcomi... Albert Y.C. Lai
- Re: Deprecated `Thread.stop()' in forth... Pavel Tolkachev
- Re: Deprecated `Thread.stop()' in forth... peter . pilgrim
- Re: Deprecated `Thread.stop()' in forthcoming JDK 1.... Michael Sinz
- Re: Deprecated `Thread.stop()' in forthcoming J... Nelson Minar
- Re: Deprecated `Thread.stop()' in forthcoming J... Pavel Tolkachev
- Re: Deprecated `Thread.stop()' in forthcoming JDK 1.... Michael Sinz