DEV Community

ChelseaLiu0822
ChelseaLiu0822

Posted on

interrupt method

Interrupting a blocked thread (wait, sleep, join) will clear the interruption status
Interrupting a normally running thread will not clear the interruption status.
The interrupt state can be used to stop a thread.

Two-stage termination model

Gracefully terminate the T2 thread in the T1 thread and give T2 a chance to take care of the aftermath (release locks and resources)

Image description

Interrupting the park thread will not clear the interruption status
After the interrupt flag is true, calling park again will fail.

Not recommended method

Image description

Will destroy the synchronized code block and cause deadlock

Top comments (0)