java - Why invoke Thread.currentThread.interrupt() in a catch InterruptException block? -


why invoke method thread.currentthread.interrupt() in catch block?

this done keep state.

when catch interruptexception , swallow it, prevent higher level methods/thread groups noticing interrupt. may cause problems.

by calling thread.currentthread().interrupt(), set interrupt flag of thread, higher level interrupt handlers notice , can handle appropriately.

java concurrency in practice discusses in more detail in chapter 7.1.3: responding interruption. rule is:

only code implements thread's interruption policy may swallow interruption request. general-purpose task , library code should never swallow interruption requests.


Comments

Popular posts from this blog

javascript - Enclosure Memory Copies -

php - Replacing tags in braces, even nested tags, with regex -