• Post Reply Bookmark Topic Watch Topic
  • New Topic

Shutting down a thread instantly - should this work?

 
John McParland
Ranch Hand
Posts: 92
Eclipse IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi folks,

in my application, when a user chooses to shutdown, I need to stop a few threads instantly which may have be sleeping. I think I have a solution for this but unfortunately there are folks who've noticed the thread is still running when the app has been shut down. I can't reproduce this behaviour and I was wondering if anyone would kindly have a look at the code below to see if there's anything obviously wrong?



The code to start the thread is;



And the code to stop is;

 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13078
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Seems to me that if you make all these other Threads daemon threads then the JVM will automatically stop them when your main user Threads exit.

See java.lang.Thread.setDaemon( true ); javadocs.

Bill

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