/**
* Create a new instance using a new {@link HashedWheelTimer} and no {@link ThreadNameDeterminer}
*
* @param bossExecutor the Executor to use for server the {@link NioClientBoss}
* @param bossCount the number of {@link NioClientBoss} instances this {@link NioClientBoss} will hold
*/
public NioClientBossPool(Executor bossExecutor, int bossCount) {
this(bossExecutor, bossCount, new HashedWheelTimer(), null);
stopTimer = true;
}
new HashedWheelTimer()调用的是Executors.DefaultThreadFactory.newThread来创建出来的线程都是non-daemon,所以造成Tomcat无法正常终止。 讲道理,这个地方我没搞明白为什么。
为了tomcat能正常终止,我把netty的代码改了。
public NioClientBossPool(Executor bossExecutor, int bossCount) {
this(bossExecutor, bossCount,
new HashedWheelTimer(new BasicThreadFactory.Builder().daemon(true).build()),
null);
stopTimer = true;
}
dump tomcat进程之后发现有两个非daemon进程,一个是tomcat主进程,另一个是Hashed wheel timer。所以tomcat无法正常终止。
寻找HashedWheelTimer构造器被调用的堆栈,发现这段代码:
new HashedWheelTimer()调用的是Executors.DefaultThreadFactory.newThread来创建出来的线程都是non-daemon,所以造成Tomcat无法正常终止。 讲道理,这个地方我没搞明白为什么。
为了tomcat能正常终止,我把netty的代码改了。
这样创建出来的HashedWheelTimer是daemon的,Tomcat能正常关闭了。但是另外一个问题还是没办反解决,那就是终止tomcat进程时dubbox的shutdown hook没有优雅地被执行。 见Issue #116