File tree 1 file changed +11
-5
lines changed
stub/src/main/java/io/grpc/stub 1 file changed +11
-5
lines changed Original file line number Diff line number Diff line change @@ -642,12 +642,15 @@ private static final class ThreadlessExecutor extends ConcurrentLinkedQueue<Runn
642
642
* Waits until there is a Runnable, then executes it and all queued Runnables after it.
643
643
*/
644
644
public void waitAndDrain () throws InterruptedException {
645
+ final Thread currentThread = Thread .currentThread ();
646
+ throwIfInterrupted (currentThread );
645
647
Runnable runnable = poll ();
646
648
if (runnable == null ) {
647
- waiter = Thread . currentThread () ;
649
+ waiter = currentThread ;
648
650
try {
649
651
while ((runnable = poll ()) == null ) {
650
652
LockSupport .park (this );
653
+ throwIfInterrupted (currentThread );
651
654
}
652
655
} finally {
653
656
waiter = null ;
@@ -662,13 +665,16 @@ public void waitAndDrain() throws InterruptedException {
662
665
} while ((runnable = poll ()) != null );
663
666
}
664
667
668
+ private static void throwIfInterrupted (Thread currentThread ) throws InterruptedException {
669
+ if (currentThread .isInterrupted ()) {
670
+ throw new InterruptedException ();
671
+ }
672
+ }
673
+
665
674
@ Override
666
675
public void execute (Runnable runnable ) {
667
676
add (runnable );
668
- final Thread waitingThread = waiter ;
669
- if (waitingThread != null ) {
670
- LockSupport .unpark (waitingThread );
671
- }
677
+ LockSupport .unpark (waiter ); // no-op if null
672
678
}
673
679
}
674
680
}
You can’t perform that action at this time.
0 commit comments