I am using following code to create a thread pool using java executor framework.
the problem here is i need a way to forcefully clean all the threads spawned by executor thread pool. I understand that shutdownNow() will not work because thread is still actively running, but i wanted to get rid of thread if it doesn't return in some specified time.
Ok, found a solution but don't know how good this is -
I have put responsibility on worker thread to check if it has got interrupted or not. This will make sure that if shutdownNow() is called which eventually interrupt the thread then work will stop working.
This works fine each time i run but to my surprise if i run in debug mode i can see wearied behavior. Some thread always left as in running mode even though log "is going to die" has got printed for all the running threads.
Any thoughts? How safe is it to implement this code?
Ya paul i know it's not safe and due to multiple complications with Stop method this was deprecated but what could be the alternative then? I have to forcefully kill thread in Executor thread pool incase they do not stop processing in fixed time.
You might want to consider reading this article. By the way it was high up in the list of links returned by Google when I used the keywords "java thread stop". You'll find other similar articles if you use those keywords; I suggest you read some of those as well.
permaculture is a more symbiotic relationship with nature so I can be even lazier. Read tiny ad:
Gift giving made easy with the permaculture playing cards