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);  
}

Get Java in a Nutshell, 5th Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.