aspose file tools
The moose likes Threads and Synchronization and the fly likes Shutting down a thread instantly - should this work? Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Threads and Synchronization
Reply Bookmark "Shutting down a thread instantly - should this work?" Watch "Shutting down a thread instantly - should this work?" New topic
Author

Shutting down a thread instantly - should this work?

John McParland
Ranch Hand

Joined: May 11, 2009
Posts: 83
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;



Passed: SCJP 6 (90%), SCJD 6
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 11862
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


Java Resources at www.wbrogden.com
 
 
subject: Shutting down a thread instantly - should this work?
 
Threads others viewed
Advice on simple threadding...
I want to execution of a Threads in sequence
My app inactive obtain the focus of windows system how?
Advice on simple threadding...
Two threads of same class instance to wait separately
IntelliJ Java IDE