> Stopping the thread will avoid the cpu utilization problem, > but your JVM is now in an unknown/unstable state. > > Connection c = dataSource.getConnection(); > try > { > synchronized (lock) > { > spin(); // ---> Stop > } > } > finally > { > c.close(); // Never done > } > > The connection leaks, I don't know what happens to the lock?
Actually the behavior you describe is the semantics of Thread.destroy() if it were actually implemented. Thread.stop() just forces the targeted thread to throw a ThreadDeath exception. This causes all finally blocks to execute, and in fact if a thread were to catch ThreadDeath, it could prevent the thread from dieing. This also causes all monitors that were aquired by the thread to be released. So, herein lies the problem. Since this exception can occur at any point, the object state of that thread is potentially corrupt. So, if the thread does not share state with other threads, it is actually quite safe. This is hardly the case though, and is a problem for BasicThreadPool because we do not know what the task is actually doing. This problem is not limited to Java, thread cancellation is a common multithreaded programming issue. Sun just chose to deprecate it because it is more than often the incorrect approach to take. -Jason > -----Original Message----- > From: [EMAIL PROTECTED] [mailto:jboss- > [EMAIL PROTECTED] On Behalf Of Adrian Brock > Sent: Saturday, February 04, 2006 5:15 PM > To: jboss-development@lists.sourceforge.net > Subject: RE: [JBoss-dev] BasicThreadPool and Thread.stop() > > On Sat, 2006-02-04 at 17:44, Scott M Stark wrote: > > It was the only way I found to implement a timeout behavior that had a > > chance of working when there were uncooperative tasks. See the > > org.jboss.test.util.test. > > ThreadPoolTaskUnitTestCase.testCompleteTimeoutWithSpinLoop as an > > example. > > There is no real solution to that problem in java. > CPU loops don't respond to thread interrupts. > > You can't even redefineClass() to add a > Thread.interrupted() > check in the misbehaving method, because it won't take affect on that > invocation. > > Stopping the thread will avoid the cpu utilization problem, > but your JVM is now in an unknown/unstable state. > > Connection c = dataSource.getConnection(); > try > { > synchronized (lock) > { > spin(); // ---> Stop > } > } > finally > { > c.close(); // Never done > } > > The connection leaks, I don't know what happens to the lock? > > A better solution would be to "automatically" trigger a reboot if you > detect a misbehaving thread. > > > > > -----Original Message----- > > From: [EMAIL PROTECTED] > > [mailto:[EMAIL PROTECTED] On Behalf Of > > Adrian Brock > > Sent: Saturday, February 04, 2006 2:33 PM > > To: jboss-development@lists.sourceforge.net > > Subject: [JBoss-dev] BasicThreadPool and Thread.stop() > > > > I don't think it is a good idea to invoke Thread.stop(). > > This has memory leak problems. > > > > Why was this introduced? The pooled threads are already daemon threads > > so they should not stop the system from exiting at shutdown. > > > > If you are not shutting down the system, then any objects > > on the stopped thread's stack are not garbage collected. > -- > 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