Summary
-------
Method `LockSupport.setCurrentBlocker` was added as part of JDK-8229442 mainly to allow implementations to maintain compatibility with tools and
utilities reporting `LockSupport.getBlocker` when threads are parked.
Problem
-------
The primary rationale for this method is to allow people to improve
compatibility with previous implementations that includes calls to `LockSupport.park`, with respect to tools expecting a particular type of blocker object to be reported in stack traces etc.
Solution
--------
`LockSupport.setCurrentBlocker` allows a given blocker to be set instead of per-park arguments for upcoming calls to park that may be performed in some other object.
Specification
-------------
/**
* Sets the object to be returned by invocations of {@link
* #getBlocker getBlocker} for the current thread. This method may
* be used before invoking the no-argument version of {@link
* LockSupport#park() park()} from non-public objects, allowing
* more helpful diagnostics, or retaining compatibility with
* previous implementations of blocking methods. Previous values
* of the blocker are not automatically restored after blocking.
* To obtain the effects of {@code park(b}}, use {@code
* setCurrentBlocker(b); park(); setCurrentBlocker(null);}
*
* @param blocker the blocker object
* @since 14
*/
public static void setCurrentBlocker(Object blocker) {
U.putObjectOpaque(Thread.currentThread(), PARKBLOCKER, blocker);
}