Yes this is a great example of the general problem of canceling a thread asynchronously. That resulting state is most likely not anticipated by the thread (No one expects a = 1 to throw an exception).
Most threading APIs try to solve this problem using cancelable points. In pthreads for example, this is any blocking thread operation (sigwait, or pthread_join). There is also a pthread_testcancel that you can use to programmatically check for cancellation. So the equivalent in Java is thread.interrupt(). However, I should clarify that what I meant is that the state of the overall system will be safe provided that the thread did not access any shared resource. So in this scenario, while it is possible that the thread will be corrupted, we don't care because it will eventually exit, and all of its resources will be freed. An example of a safe use of Thread.stop is where the target thread is doing some long running mathematical calculation. I am in no way, endorsing the use of thread cancellation. Even in scenarios where it is safe to use it, the code can be easily rewritten to periodically poll a notification variable. -Jason > -----Original Message----- > From: [EMAIL PROTECTED] [mailto:jboss- > [EMAIL PROTECTED] On Behalf Of Adrian Brock > Sent: Monday, February 06, 2006 3:25 AM > To: jboss-development@lists.sourceforge.net > Subject: RE: [JBoss-dev] BasicThreadPool and Thread.stop() > > Thanks for the clarification. Re-reading this: > http://java.sun.com/j2se/1.5.0/docs/guide/misc/threadPrimitiveDeprecatio n. > html > > This says it is never safe. 2 examples: > > lock = lock(); > // Thread death here is bad! > try > { > ... > } > finally > { > lock.unlock(); > } > > An attempt to fix it > > lock = null; > try > { > lock = lock(); > ... > } > finally > { > if (lock != null) > lock.unlock(); > } > > But it won't work, because this code is really: > > lock = null; > try > { > lock(); > // Thread death here is bad! > lock = popResultFromThreadStack(); > ... > } > finally > { > if (lock != null) > lock.unlock(); > } > -- > xxxxxxxxxxxxxxxxxxxxxxxx > Adrian Brock > Chief Scientist > JBoss Inc. > xxxxxxxxxxxxxxxxxxxxxxxx > > > > ------------------------------------------------------- > This SF.net email is sponsored by: Splunk Inc. Do you grep through log > files > for problems? Stop! Download the new AJAX search engine that makes > searching your log files as easy as surfing the web. DOWNLOAD SPLUNK! > http://sel.as-us.falkag.net/sel?cmd=lnk&kid=103432&bid=230486&dat=121642 > _______________________________________________ > JBoss-Development mailing list > JBoss-Development@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/jboss-development ------------------------------------------------------- This SF.net email is sponsored by: Splunk Inc. Do you grep through log files for problems? Stop! Download the new AJAX search engine that makes searching your log files as easy as surfing the web. DOWNLOAD SPLUNK! http://sel.as-us.falkag.net/sel?cmd=lnk&kid3432&bid#0486&dat1642 _______________________________________________ JBoss-Development mailing list JBoss-Development@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/jboss-development