Skip to content

Commit

Permalink
Reduce lock contention in Thread.getAndClearInterrupt
Browse files Browse the repository at this point in the history
Lock contention in Thread.getAndClearInterrupt is reduced by
acquiring the lock only when the value of the Thread.interrupted
field is true.

Related: eclipse-openj9/openj9#20414

Signed-off-by: Babneet Singh <[email protected]>
  • Loading branch information
babsingh committed Oct 28, 2024
1 parent 006fde1 commit dd35ec6
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions src/java.base/share/classes/java/lang/Thread.java
Original file line number Diff line number Diff line change
Expand Up @@ -1805,14 +1805,17 @@ boolean getAndClearInterrupt() {
if (com.ibm.oti.vm.VM.isJVMInSingleThreadedMode()) {
return interruptedImpl();
}
synchronized (interruptLock) {
boolean oldValue = interrupted;
if (oldValue) {
interrupted = false;
clearInterruptEvent();
boolean oldValue = interrupted;
if (oldValue) {
synchronized (interruptLock) {
oldValue = interrupted;
if (oldValue) {
interrupted = false;
clearInterruptEvent();
}
}
return oldValue;
}
return oldValue;
}

/**
Expand Down

0 comments on commit dd35ec6

Please sign in to comment.