• Post Reply Bookmark Topic Watch Topic
  • New Topic

Stopping threads  RSS feed

 
victor thor
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I create a set of threads that are started via an ExecutorService. If one thread fails I want to stop all the remaining thread. For this I call the shutdownNow() method.
Now the thread call() method is something like this:

My "processing steps" may involve while loops.

If the executor sends the interrupt message should I test Thread.currentThread().isInterruped() before each of my processing steps and throw an InterruptedException, somthing like this?


Or there is another possible solution?

Thanks in advance.

 
Steve Luke
Bartender
Posts: 4181
22
IntelliJ IDE Java Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You will need to periodically check the Thread.interrupted() or currentThread.isInterrupted() methods to respond to the shutdown. But you don't need to throw an InterruptedException. Instead you can just return from the method:

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