This is the mail archive of the
java-discuss@sources.redhat.com
mailing list for the Java project.
Re: Precise GC (was Re: cannot build libjava/gnu/gcj/xlib/natClip.cc)
> > Too bad Thread.stop is deprecated by Sun, and libgcj doesn't implement it
> > (contradicting the remark in Thread.java). I consider this a serious flaw in
> > Java.
>
> I was thinking about this recently and concluded that we should implement
> Thread.stop(). Clearly there are cases, particularly when you don't have direct
> control over all the code being run, where you need to shut down some misbehaving
> thread forcefully and interrupt() isn't good enough.
Have you read Doug Lea's book (Concurrent programming on Java) on this subject?
stop() doesn't give you any benefit over interrupt() because
1) a bad thread can catch a ThreadDeath exception the same way
it can catch an InterruptedException.
2) stopping a thread asynchronously is almost certain to corrupt
the state of your system.
If you have a misbehaving thread you want to shutdown, you want to:
1) be nice and start with thread.interrupt() and wait a little bit
2) alter the SecurityManager to deny *all* requests for this
thread and at the same time set its priority to the lowest value.
This should limit damages and shut down most of the threads.
3) If none of the above works, call Thread.destroy() which is
not deprecated.
Bottom line: Thread.stop() is useless and dangerous.
Cedric