0

If thread is interrupted in java, I know we should set its flag back to interrupted, wrap up the things(any cleaning) and exit.

But I would like to know -

  1. What happens to that thread after that?
  2. Who should clear the status of the flag if it is one of the thread from thread pool and if I don't want to exit the application.
  3. I might want that thread to be cleaned or just kill that thread and create new clean thread? Or that thread is useless forever till application closes down?
  4. Does executor service or whoever created thread takes the responsibility and replace thread with new clean thread?
Andy Turner
  • 137,514
  • 11
  • 162
  • 243
Abhi
  • 1
  • 1
  • 2
    Threads can be interrupted for many reasons, not all of which imply the thread must be terminated... it's not clear what you're asking. – Jim Garrison Dec 22 '17 at 19:07
  • My question is what is the life cycle of thread after thread is interrupted. I have seen code where people just set the flag back to interrupted after catching InterruptedException. I am more interested in knowing what happens to that thread after that (and suppose I want that thread to get new tasks as a new clean thread) – Abhi Dec 22 '17 at 20:17
  • @Abhi you don't reset the flag after catching `InterruptedException`, you *set* it, if appropriate. `InterruptedException` doesn't mean the interrupted flag is set. Take a look at its source code: you may be surprised by how little code it contains. – Andy Turner Dec 22 '17 at 20:22

0 Answers0