• Post Reply Bookmark Topic Watch Topic
  • New Topic

ThreadDeath on a stop( )  RSS feed

 
Jayadev Pulaparty
Ranch Hand
Posts: 662
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm calling the stop() method on a running thread. I'm not really bothered about recovery of the state of the task being performed on that thread. I'm getting a ThreadDeath error thrown. I've gone through the thread API documentation and it recommended not to catch the error. I'm following suit.

My question is, is it safe from a JVM standpoint to ignore this error and continue with other tasks in the system, i.e., is calling stop() going to cause any instability in the system?

Can someone please throw some light on this?

Thanks.
 
Peter Chase
Ranch Hand
Posts: 1970
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You presumably know that stop() is strongly deprecated. You really shouldn't be calling it. Why do you think you need to call it?

Assuming you're in the 0.1% of people who really need to call it, not the 99.9% who only think they do, but could actually do something different and much better, then it sounds like you're handling it as correctly as it is possible to handle something you shouldn't do in the first place. You certainly should not catch the ThreadDeath.

My understanding is that calling stop() will not break the JVM itself. It only risks fouling up any objects used by that thread, which may also be used by other threads. It is very difficult to be sure there are no such objects. Even if there are none in your code, can you be sure there are none in API code on which you implicitly depend?
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!