dubbox icon indicating copy to clipboard operation
dubbox copied to clipboard

消费端使用dubbox,部署在Tomcat中,Tomcat主进程无法终止

Open amnyx opened this issue 9 years ago • 5 comments

dump tomcat进程之后发现有两个非daemon进程,一个是tomcat主进程,另一个是Hashed wheel timer。所以tomcat无法正常终止。

寻找HashedWheelTimer构造器被调用的堆栈,发现这段代码:

    /**
     * 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;
    }

这样创建出来的HashedWheelTimer是daemon的,Tomcat能正常关闭了。但是另外一个问题还是没办反解决,那就是终止tomcat进程时dubbox的shutdown hook没有优雅地被执行。 见Issue #116

amnyx avatar Apr 21 '16 12:04 amnyx

非常感谢,解决了遇到的问题

wjn161 avatar Aug 30 '16 04:08 wjn161

这么做没问题吧?为啥只有以前没这个问题呢。

quhw avatar Oct 16 '16 16:10 quhw

在tomcat中一直有这个问题,在jetty中就没有这个问题

ian4hu avatar Oct 18 '16 01:10 ian4hu

mark一下

zyoo avatar Jul 04 '17 07:07 zyoo

dubbo官方使用的是org.jboss.netty 3.25 org.apache.zookeeper使用的是io.netty , 在使用jboss.netty的情况下,可以正常关闭

sxc9870 avatar Nov 06 '17 08:11 sxc9870