Java Practices->Handle InterruptedException
In multi-threaded code, threads can often block; the thread pauses execution until some external condition is met, such as :- a lock is released
- another thread completes an operation
- some I/O operation completes
- and so on...
Threads can be interrupted. An interrupt asks a thread to stop what it's doing in an orderly fashion. However, the exact response to the interrupt depends on the thread's state, and how the thread is implemented:
if the thread is currently blocking stop blocking early throw InterruptedException else thread is doing real work thread's interrupted status is set to true if thread polls isInterrupted() periodically (which is preferred) orderly cleanup and stop execution throw InterruptedException else regular execution continues
Read full article from Java Practices->Handle InterruptedException
No comments:
Post a Comment