Name
LockSupport
Synopsis
This class
provides a low-level alternative to the deprecated methods
Thread.suspend( ) and Thread.resume(
). The park( ), parkNanos(
), and parkUntil( ) methods suspend, or
park, the thread until it is unparked by another thread with
unpark( ), or until it is interrupted by another
thread, or until the specified time elapses. parkNanos(
) parks the thread for the specified number of nanoseconds.
parkUntil( ) parks the thread until the specified
time, using the millisecond representation of
System.currentTimeMillis( ). Any call to these
parking methods may return spuriously, so it is important to call
park( ) in a loop that can repark the thread if it
should not have resumed.
Unpark a thread with the unpark( ) method. Note
that while the parking methods affect the current thread, the
unpark( ) method affects the thread you specify.
If the specified thread is not parked, the next time that thread
calls one of the park( ) methods, it returns
immediately instead of blocking.
public class LockSupport { // No Constructor // Public Class Methods public static void park( ); public static void parkNanos(long nanos); public static void parkUntil(long deadline); public static void unpark(Thread thread); }
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access