java - What is a good practice of checking InterruptedException? -


i'm new java world, bear me if dumb question.

i saw code in run() method of runnable object.

try {     if (thread.interrupted()) {        throw new interruptedexception();     }      //       if (thread.interrupted()) {         throw new interruptedexception();     }      //       if (thread.interrupted()) {         throw new interruptedexception();     }      // , on  } catch (interruptedexception e){      // handle exception } {      // release resource } 

how often, , should check thread interruption, practice it?

it's not sprinkle throughout code. however, if expecting able cancel asynchronous task, may necessary periodically check interruption. in other words, it's typically add after fact when identify body of code needs more responsive interruption.


Comments

Popular posts from this blog

android - getbluetoothservice() called with no bluetoothmanagercallback -

sql - ASP.NET SqlDataSource, like on SelectCommand -

ios - Undefined symbols for architecture armv7: "_OBJC_CLASS_$_SSZipArchive" -