Description
I adapt your code to my needs. I have a fork in private repository and mostly trying to use spring-boot-dependcies to manage with jar hell in dependent projects.
So, I've met some tests failing. GenericItemSourcePoolTest.multipleThreadsGetPooledWhenResizePolicyEventuallyCopeWithTheLoad.
After investigation I can report some notes about implementation.
I'd change (and did locally) method GenericItemSourcePool.unlatchAndResetResizing to this variant:
// you cannot count down latch while resizing is true (in progress). see comments in #awaitResize method
private final Consumer<Boolean> unlatchAndResetResizing = result -> {
var latch = this.countDownLatch.get();
resizing.set(false);
latch.countDown();
};
And my comments for awaitResize method:
// Here some notes about unlatchAndResetResizing. It will fail if another thread is superfast. Look at the following use case:
// [Thread A] starts resizing (set resizing to true and adds latch, for instance named "Latch1"). The process begins
// [Thread B] got resizing=true, pass to await - take Latch1 and wait for timeout
// [Thread A] finish the process and begins "unlatchAndResetResizing" - down Latch1, and ...
// [Thread B] Latch1 is free! go down to resize again. resizing is still true, so take the latch (latch is still Latch1), awaits it. Latch1 is free! go down to resize again, etc.. And get `(depth > maxRetries)` error
// [Thread A] ... and we are setting `resizing` to false. At last!
// let's allow only one thread to get in
if (resizing.compareAndSet(false, true)) {
countDownLatch.set(new CountDownLatch(1));
return resize(unlatchAndResetResizing);
}
Configuration
Just development environment. JDK11 and Maven, no more
Runtime (please complete the following information):
Module name and version: current HEAD version of repository
Framework/server/module system used: nope
JVM: OpenJDK 64-Bit Server VM (build 11.0.24+8-post-Ubuntu-1ubuntu324.04.1, mixed mode, sharing)
Description I adapt your code to my needs. I have a fork in private repository and mostly trying to use spring-boot-dependcies to manage with jar hell in dependent projects.
So, I've met some tests failing.
GenericItemSourcePoolTest.multipleThreadsGetPooledWhenResizePolicyEventuallyCopeWithTheLoad
.After investigation I can report some notes about implementation. I'd change (and did locally) method GenericItemSourcePool.unlatchAndResetResizing to this variant:
And my comments for
awaitResize
method:Configuration Just development environment. JDK11 and Maven, no more
Runtime (please complete the following information):