< prev index next >

src/java.base/share/classes/java/util/concurrent/locks/AbstractQueuedSynchronizer.java

Print this page
8234131: Miscellaneous changes imported from jsr166 CVS 2021-01
Reviewed-by: martin

@@ -38,10 +38,11 @@
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Date;
 import java.util.concurrent.TimeUnit;
 import java.util.concurrent.ForkJoinPool;
+import java.util.concurrent.RejectedExecutionException;
 import jdk.internal.misc.Unsafe;
 
 /**
  * Provides a framework for implementing blocking locks and related
  * synchronizers (semaphores, events, etc) that rely on

@@ -135,17 +136,17 @@
  * <p>Even though this class is based on an internal FIFO queue, it
  * does not automatically enforce FIFO acquisition policies.  The core
  * of exclusive synchronization takes the form:
  *
  * <pre>
- * Acquire:
+ * <em>Acquire:</em>
  *     while (!tryAcquire(arg)) {
  *        <em>enqueue thread if it is not already queued</em>;
  *        <em>possibly block current thread</em>;
  *     }
  *
- * Release:
+ * <em>Release:</em>
  *     if (tryRelease(arg))
  *        <em>unblock the first queued thread</em>;
  * </pre>
  *
  * (Shared mode is similar but may involve cascading signals.)

@@ -1563,17 +1564,22 @@
          */
         public final void awaitUninterruptibly() {
             ConditionNode node = new ConditionNode();
             int savedState = enableWait(node);
             LockSupport.setCurrentBlocker(this); // for back-compatibility
-            boolean interrupted = false;
+            boolean interrupted = false, rejected = false;
             while (!canReacquire(node)) {
                 if (Thread.interrupted())
                     interrupted = true;
                 else if ((node.status & COND) != 0) {
                     try {
+                        if (rejected)
+                            node.block();
+                        else
                         ForkJoinPool.managedBlock(node);
+                    } catch (RejectedExecutionException ex) {
+                        rejected = true;
                     } catch (InterruptedException ie) {
                         interrupted = true;
                     }
                 } else
                     Thread.onSpinWait();    // awoke while enqueuing

@@ -1602,18 +1608,23 @@
             if (Thread.interrupted())
                 throw new InterruptedException();
             ConditionNode node = new ConditionNode();
             int savedState = enableWait(node);
             LockSupport.setCurrentBlocker(this); // for back-compatibility
-            boolean interrupted = false, cancelled = false;
+            boolean interrupted = false, cancelled = false, rejected = false;
             while (!canReacquire(node)) {
                 if (interrupted |= Thread.interrupted()) {
                     if (cancelled = (node.getAndUnsetStatus(COND) & COND) != 0)
                         break;              // else interrupted after signal
                 } else if ((node.status & COND) != 0) {
                     try {
+                        if (rejected)
+                            node.block();
+                        else
                         ForkJoinPool.managedBlock(node);
+                    } catch (RejectedExecutionException ex) {
+                        rejected = true;
                     } catch (InterruptedException ie) {
                         interrupted = true;
                     }
                 } else
                     Thread.onSpinWait();    // awoke while enqueuing
< prev index next >