Make it clear that HashedWheelTimer only support millis. (#8322)
Motivation: HWT does not support anything smaller then 1ms so we should make it clear that this is the case. Modifications: Log a warning if < 1ms is used. Result: Less suprising behaviour.
This commit is contained in:
parent
359390d04c
commit
bde2865ef8
@ -84,6 +84,7 @@ public class HashedWheelTimer implements Timer {
|
||||
private static final AtomicInteger INSTANCE_COUNTER = new AtomicInteger();
|
||||
private static final AtomicBoolean WARNED_TOO_MANY_INSTANCES = new AtomicBoolean();
|
||||
private static final int INSTANCE_COUNT_LIMIT = 64;
|
||||
private static final long MILLISECOND_NANOS = TimeUnit.MILLISECONDS.toNanos(1);
|
||||
private static final ResourceLeakDetector<HashedWheelTimer> leakDetector = ResourceLeakDetectorFactory.instance()
|
||||
.newResourceLeakDetector(HashedWheelTimer.class, 1);
|
||||
|
||||
@ -259,14 +260,25 @@ public class HashedWheelTimer implements Timer {
|
||||
mask = wheel.length - 1;
|
||||
|
||||
// Convert tickDuration to nanos.
|
||||
this.tickDuration = unit.toNanos(tickDuration);
|
||||
long duration = unit.toNanos(tickDuration);
|
||||
|
||||
// Prevent overflow.
|
||||
if (this.tickDuration >= Long.MAX_VALUE / wheel.length) {
|
||||
if (duration >= Long.MAX_VALUE / wheel.length) {
|
||||
throw new IllegalArgumentException(String.format(
|
||||
"tickDuration: %d (expected: 0 < tickDuration in nanos < %d",
|
||||
tickDuration, Long.MAX_VALUE / wheel.length));
|
||||
}
|
||||
|
||||
if (duration < MILLISECOND_NANOS) {
|
||||
if (logger.isWarnEnabled()) {
|
||||
logger.warn("Configured tickDuration %d smaller then %d, using 1ms.",
|
||||
tickDuration, MILLISECOND_NANOS);
|
||||
}
|
||||
this.tickDuration = MILLISECOND_NANOS;
|
||||
} else {
|
||||
this.tickDuration = duration;
|
||||
}
|
||||
|
||||
workerThread = threadFactory.newThread(worker);
|
||||
|
||||
leak = leakDetection || !workerThread.isDaemon() ? leakDetector.track(this) : null;
|
||||
|
Loading…
Reference in New Issue
Block a user