diff --git a/src/java.base/share/classes/java/lang/Thread.java b/src/java.base/share/classes/java/lang/Thread.java index f7c7b524b6c..a8cfa9849d4 100644 --- a/src/java.base/share/classes/java/lang/Thread.java +++ b/src/java.base/share/classes/java/lang/Thread.java @@ -1813,15 +1813,14 @@ final void clearInterrupt() { } boolean getAndClearInterrupt() { - boolean oldValue = interrupted; - // We may have been interrupted the moment after we read the field, - // so only clear the field if we saw that it was set and will return - // true; otherwise we could lose an interrupt. - if (oldValue) { - interrupted = false; - clearInterruptEvent(); + synchronized (interruptLock) { + boolean oldValue = interrupted; + if (oldValue) { + interrupted = false; + clearInterruptEvent(); + } + return oldValue; } - return oldValue; } /**