src/share/classes/java/util/concurrent/locks/LockSupport.java

Print this page




 183     public static void park(Object blocker) {
 184         Thread t = Thread.currentThread();
 185         setBlocker(t, blocker);
 186         unsafe.park(false, 0L);
 187         setBlocker(t, null);
 188     }
 189 
 190     /**
 191      * Disables the current thread for thread scheduling purposes, for up to
 192      * the specified waiting time, unless the permit is available.
 193      *
 194      * <p>If the permit is available then it is consumed and the call
 195      * returns immediately; otherwise the current thread becomes disabled
 196      * for thread scheduling purposes and lies dormant until one of four
 197      * things happens:
 198      *
 199      * <ul>
 200      * <li>Some other thread invokes {@link #unpark unpark} with the
 201      * current thread as the target; or
 202      *
 203      * <li>Some other thread {@linkplain Thread#interrupt interrupts} the current
 204      * thread; or
 205      *
 206      * <li>The specified waiting time elapses; or
 207      *
 208      * <li>The call spuriously (that is, for no reason) returns.
 209      * </ul>
 210      *
 211      * <p>This method does <em>not</em> report which of these caused the
 212      * method to return. Callers should re-check the conditions which caused
 213      * the thread to park in the first place. Callers may also determine,
 214      * for example, the interrupt status of the thread, or the elapsed time
 215      * upon return.
 216      *
 217      * @param blocker the synchronization object responsible for this
 218      *        thread parking
 219      * @param nanos the maximum number of nanoseconds to wait
 220      * @since 1.6
 221      */
 222     public static void parkNanos(Object blocker, long nanos) {
 223         if (nanos > 0) {
 224             Thread t = Thread.currentThread();




 183     public static void park(Object blocker) {
 184         Thread t = Thread.currentThread();
 185         setBlocker(t, blocker);
 186         unsafe.park(false, 0L);
 187         setBlocker(t, null);
 188     }
 189 
 190     /**
 191      * Disables the current thread for thread scheduling purposes, for up to
 192      * the specified waiting time, unless the permit is available.
 193      *
 194      * <p>If the permit is available then it is consumed and the call
 195      * returns immediately; otherwise the current thread becomes disabled
 196      * for thread scheduling purposes and lies dormant until one of four
 197      * things happens:
 198      *
 199      * <ul>
 200      * <li>Some other thread invokes {@link #unpark unpark} with the
 201      * current thread as the target; or
 202      *
 203      * <li>Some other thread {@linkplain Thread#interrupt interrupts}
 204      * the current thread; or
 205      *
 206      * <li>The specified waiting time elapses; or
 207      *
 208      * <li>The call spuriously (that is, for no reason) returns.
 209      * </ul>
 210      *
 211      * <p>This method does <em>not</em> report which of these caused the
 212      * method to return. Callers should re-check the conditions which caused
 213      * the thread to park in the first place. Callers may also determine,
 214      * for example, the interrupt status of the thread, or the elapsed time
 215      * upon return.
 216      *
 217      * @param blocker the synchronization object responsible for this
 218      *        thread parking
 219      * @param nanos the maximum number of nanoseconds to wait
 220      * @since 1.6
 221      */
 222     public static void parkNanos(Object blocker, long nanos) {
 223         if (nanos > 0) {
 224             Thread t = Thread.currentThread();