Skip to content

Commit

Permalink
Change chunk snapshot waiting to use future.get(timeout)
Browse files Browse the repository at this point in the history
LockSupport will not wake up immediately if the future
is completed, which may have caused a throughput loss
  • Loading branch information
Spottedleaf authored and jpenilla committed Jun 21, 2022
1 parent b5bc463 commit 44ab9a6
Showing 1 changed file with 4 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import java.util.concurrent.ExecutorService;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.locks.LockSupport;
import java.util.function.BooleanSupplier;
Expand Down Expand Up @@ -489,12 +490,9 @@ private static int applyDepthCheckerboard(final double fluidCountY, final int co
if (!this.running()) {
return null;
}
boolean interrupted = Thread.interrupted();
Thread.yield();
LockSupport.parkNanos(TimeUnit.MILLISECONDS.toNanos(Math.min(5, failures)));
if (interrupted) {
Thread.currentThread().interrupt();
}
try {
future.get(Math.min(50, failures), TimeUnit.MILLISECONDS);
} catch (InterruptedException | TimeoutException | ExecutionException ignore) {}
}
return future.join();
}
Expand Down

0 comments on commit 44ab9a6

Please sign in to comment.