Skip to content

Commit

Permalink
[optimize] borrow didn't pick closing node.
Browse files Browse the repository at this point in the history
  • Loading branch information
w.vela committed Dec 26, 2017
1 parent e3481ec commit a87f995
Showing 1 changed file with 7 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ public Pooled<T> borrow() {
throw new IllegalStateException("pool is closed.");
}
CounterWrapper counterWrapper = currentAvailable.stream() //
.filter(it -> !it.isClosing()) //
.min(comparingInt(CounterWrapper::currentConcurrency)) //
.orElseThrow(() -> new IllegalStateException("pool is closed."));
counterWrapper.enter();
Expand Down Expand Up @@ -256,13 +257,17 @@ public void close() throws Exception {
}
}

private boolean isClosing() {
return closing;
}

@Override
public int currentConcurrency() {
return concurrency.intValue();
}

private void enter() {
concurrency.incrementAndGet();
concurrency.getAndIncrement();
}

private void leave() {
Expand All @@ -282,7 +287,7 @@ private static class SimpleStatsKey<V> implements StatsKey<V> {
SimpleStatsKey(Class<V> type) {
this.type = type;
}

V cast(Object obj) {
return type.cast(obj);
}
Expand Down

0 comments on commit a87f995

Please sign in to comment.