Skip to content

Commit

Permalink
Add synchronization around boolean lock to avoid clash of threads.
Browse files Browse the repository at this point in the history
  • Loading branch information
raphw committed Jul 11, 2024
1 parent 4606274 commit 6dfa7ec
Showing 1 changed file with 9 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2611,14 +2611,16 @@ public boolean acquire() {
AtomicBoolean lock = this.lock.length == 1
? this.lock[0]
: this.lock[System.identityHashCode(Thread.currentThread()) % this.lock.length];
if (lock.compareAndSet(true, false)) {
try {
return doAcquire();
} finally {
lock.set(true);
synchronized (lock) { // avoid that different class loaders skip class loading of each other
if (lock.compareAndSet(true, false)) {
try {
return doAcquire();
} finally {
lock.set(true);
}
} else {
return false;
}
} else {
return false;
}
}

Expand Down

0 comments on commit 6dfa7ec

Please sign in to comment.