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)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay