io.netty.util.HashedWheelTimer | You are creating too many HashedWheelTimer instances. HashedWheelTimer is a shared resource that must be reused across the JVM,so that only a few instances are created.
查看io.netty.util.HashedWheelTimer 源码找到以下代码块
// 这里是创建上限值(警告阈值)privatestaticfinalint INSTANCE_COUNT_LIMIT =64;publicHashedWheelTimer(
ThreadFactory threadFactory,long tickDuration, TimeUnit unit,int ticksPerWheel,boolean leakDetection,long maxPendingTimeouts){
ObjectUtil.checkNotNull(threadFactory,"threadFactory");
ObjectUtil.checkNotNull(unit,"unit");
ObjectUtil.checkPositive(tickDuration,"tickDuration");
ObjectUtil.checkPositive(ticksPerWheel,"ticksPerWheel");// Normalize ticksPerWheel to power of two and initialize the wheel.
wheel =createWheel(ticksPerWheel);
mask = wheel.length -1;// Convert tickDuration to nanos.long duration = unit.toNanos(tickDuration);// Prevent overflow.if(duration >= Long.MAX_VALUE / wheel.length){thrownewIllegalArgumentException(String.format("tickDuration: %d (expected: 0 < tickDuration in nanos < %d",
tickDuration, Long.MAX_VALUE / wheel.length));}if(duration < MILLISECOND_NANOS){
logger.warn("Configured tickDuration {} smaller then {}, 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;this.maxPendingTimeouts = maxPendingTimeouts;// 这里判断创建了多少实例if(INSTANCE_COUNTER.incrementAndGet()> INSTANCE_COUNT_LIMIT &&
WARNED_TOO_MANY_INSTANCES.compareAndSet(false,true)){// 打印警告日志reportTooManyInstances();}}// 这是打印警告日志的方法(实际打印的是error日志)privatestaticvoidreportTooManyInstances(){if(logger.isErrorEnabled()){
String resourceType =simpleClassName(HashedWheelTimer.class);
logger.error("You are creating too many "+ resourceType +" instances. "+
resourceType +" is a shared resource that must be reused across the JVM,"+"so that only a few instances are created.");}}