dangdangdotcom / dubbox

Dubbox now means Dubbo eXtensions, and it adds features like RESTful remoting, Kyro/FST serialization, etc to the Dubbo service framework.
http://dangdangdotcom.github.io/dubbox
Apache License 2.0
4.89k stars 2.06k forks source link

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

Open beefluga opened 8 years ago

beefluga commented 8 years ago

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

wjn161 commented 8 years ago

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

quhw commented 7 years ago

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

ian4hu commented 7 years ago

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

zyoo commented 7 years ago

mark一下

sxc9870 commented 6 years ago

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