• Post Reply Bookmark Topic Watch Topic
  • New Topic

How to terminate a blocked thread with a shutdown hook

 
chris liao
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I am in trouble, Please help me! I want to termiate a blocked thread with

shutdownHook.But when the main thread was over,my shutdown hook still

didn't work. Why ? My source code is below, please help me to resolve the

question. Thanks!





[ UD: added CODE tags ]
[ July 14, 2007: Message edited by: Ulf Dittmer ]
 
Ulf Dittmer
Rancher
Posts: 42970
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The reason that the shutdown hook doesn't run is that the JVM is not actually shutting down, and the reason for that is that "targetThread" is not a daemon thread. The JVM will shut down if and when all alive threads are daemon threads, which is not the case here.

Note that I've added CODE tags to your post: UseCodeTags. They make reading code much easier.
 
chris liao
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, Ulf Dittmer,

Thanks!
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!