Java - (Thread) Interrupt

Java Conceptuel Diagram

About

Instruction Cycle - Interrupt in Java

Java

Many methods that throw InterruptedException, such as sleep, are designed to cancel their current operation and return immediately when an interrupt is received.

A thread sends an interrupt by invoking interrupt on the Thread object for the thread to be interrupted.

The Interrupt Status Flag

The interrupt mechanism is implemented using an internal flag known as the interrupt status. Invoking Thread.interrupt sets this flag. When a thread checks for an interrupt by invoking the static method Thread.interrupted, interrupt status is cleared. The non-static isInterrupted method, which is used by one thread to query the interrupt status of another, does not change the interrupt status flag.

By convention, any method that exits by throwing an InterruptedException clears interrupt status when it does so. However, it's always possible that interrupt status will immediately be set again, by another thread invoking interrupt.

Documentation / Reference





Discover More
Java Conceptuel Diagram
Java Concurrency - (Thread) Execution Suspension

in java Thread.sleep Thread.join Object.wait Many methods that suspend execution throw an InterruptedException.



Share this page:
Follow us:
Task Runner