• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • paul wheaton
Saloon Keepers:
  • Ganesh Patekar
  • Frits Walraven
  • Tim Moores
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Stephan van Hulst
  • salvin francis
  • Tim Holloway

Shutting down a thread instantly - should this work?  RSS feed

 
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;

 
Author and all-around good cowpoke
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

 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!