After researching JEP: 312 Thread-Local-Handshakes and reading the excellent comments to this question, here is a quick summary.
-
It is a performance enhancement which cannot be used directly by developers:
A
handshake
mechanism is proposed as an optimisation of theHotspot safepoints
mechanism.The former allows threads in a safepoint to continue executing immediately after performing a regulatory operation (the handshake callback).
The latter forces all threads to block on a safepoint in order for critical operations to take place (such as YoungGen GC or the STW parts of a Full GC). The threads are released only after the critical operation has completed its execution.
- This JEP is not related to thread termination APIs such as Thread.destroy(). Since this subject has been raised, I’ll add a few articles on thread termination in the references below.
OP Commentators:
JimmyB , Andy Turner , skomisa , Alexander Bollaert
References:
- Task Management history for JEP: 312 (JDK-8185640)
- OpenJDK discussion on JDK-8185640
- Safepoints in Hotspot JVM
- Java GC safepoints
- How to kill a Java Thread
- Shutting down threads cleanly