diff --git a/common/src/main/java/io/netty/util/HashedWheelTimer.java b/common/src/main/java/io/netty/util/HashedWheelTimer.java index 914b870b33..889d7f1599 100644 --- a/common/src/main/java/io/netty/util/HashedWheelTimer.java +++ b/common/src/main/java/io/netty/util/HashedWheelTimer.java @@ -197,11 +197,13 @@ public class HashedWheelTimer implements Timer { mask = wheel.length - 1; // Convert tickDuration to nanos. - this.tickDuration = tickDuration = unit.toNanos(tickDuration); + this.tickDuration = unit.toNanos(tickDuration); // Prevent overflow. - if (tickDuration == Long.MAX_VALUE || tickDuration >= Long.MAX_VALUE / wheel.length) { - throw new IllegalArgumentException("tickDuration is too long: " + tickDuration + ' ' + unit); + if (this.tickDuration >= Long.MAX_VALUE / wheel.length) { + throw new IllegalArgumentException(String.format( + "tickDuration: %d (expected: 0 < tickDuration in nanos < %d", + tickDuration, Long.MAX_VALUE / wheel.length)); } workerThread = threadFactory.newThread(worker); @@ -339,7 +341,7 @@ public class HashedWheelTimer implements Timer { if (workerState.get() == WORKER_STATE_SHUTDOWN) { throw new IllegalStateException("Cannot enqueue after shutdown"); } - final int stopIndex = (int) ((wheelCursor + relativeIndex) & mask); + final int stopIndex = (int) (wheelCursor + relativeIndex & mask); timeout.stopIndex = stopIndex; timeout.remainingRounds = remainingRounds; wheel[stopIndex].add(timeout); @@ -462,7 +464,7 @@ public class HashedWheelTimer implements Timer { // // See https://github.com/netty/netty/issues/356 if (PlatformDependent.isWindows()) { - sleepTimeMs = (sleepTimeMs / 10) * 10; + sleepTimeMs = sleepTimeMs / 10 * 10; } try {