提交 aeea8c9f authored 作者: Noel Grandin's avatar Noel Grandin

fix potential race in incrementing executingThreadCounter

上级 c5453323
...@@ -309,21 +309,27 @@ public abstract class Page implements Cloneable ...@@ -309,21 +309,27 @@ public abstract class Page implements Cloneable
final List<Future<?>> futures = new ArrayList<>(len); final List<Future<?>> futures = new ArrayList<>(len);
for (int i = 0; i <= len; i++) { for (int i = 0; i <= len; i++) {
final long childPagePos = buff.getLong(); final long childPagePos = buff.getLong();
if (executingThreadCounter.get() >= executorService.getMaximumPoolSize()) { for (;;) {
collector.visit(childPagePos, executorService, executingThreadCounter); int counter = executingThreadCounter.get();
} else { if (counter >= executorService.getMaximumPoolSize()) {
executingThreadCounter.incrementAndGet(); collector.visit(childPagePos, executorService, executingThreadCounter);
Future<?> f = executorService.submit(new Runnable() { break;
@Override } else {
public void run() { if (executingThreadCounter.compareAndSet(counter, counter + 1)) {
try { Future<?> f = executorService.submit(new Runnable() {
collector.visit(childPagePos, executorService, executingThreadCounter); @Override
} finally { public void run() {
executingThreadCounter.decrementAndGet(); try {
} collector.visit(childPagePos, executorService, executingThreadCounter);
} finally {
executingThreadCounter.decrementAndGet();
}
}
});
futures.add(f);
break;
} }
}); }
futures.add(f);
} }
} }
for (Future<?> f : futures) { for (Future<?> f : futures) {
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论