From 95c705f60c1833b07f1fed6e08a08d7bee7f0971 Mon Sep 17 00:00:00 2001 From: Nick Palmer Date: Fri, 29 Sep 2023 14:18:15 +0100 Subject: [PATCH] Use a monotonic clock for checking timeout on shutdown --- src/main/java/com/lmax/disruptor/dsl/Disruptor.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/lmax/disruptor/dsl/Disruptor.java b/src/main/java/com/lmax/disruptor/dsl/Disruptor.java index 4ad200c98..f202d333a 100644 --- a/src/main/java/com/lmax/disruptor/dsl/Disruptor.java +++ b/src/main/java/com/lmax/disruptor/dsl/Disruptor.java @@ -404,10 +404,10 @@ public void shutdown() */ public void shutdown(final long timeout, final TimeUnit timeUnit) throws TimeoutException { - final long timeOutAt = System.currentTimeMillis() + timeUnit.toMillis(timeout); + final long timeOutAt = System.nanoTime() + timeUnit.toNanos(timeout); while (hasBacklog()) { - if (timeout >= 0 && System.currentTimeMillis() > timeOutAt) + if (timeout >= 0 && System.nanoTime() > timeOutAt) { throw TimeoutException.INSTANCE; }