关闭netty 4应用程序会抛出RejectedExecutionException

时间:2013-12-12 10:50:35

标签: java netty

让我们假设以下管道:

pipeline.addLast(MY_STATELESS_DECODER);
pipeline.addLast(SHARED_EVENT_EXECUTOR, MY_STATELESS_BUSINESS_LOGIC_HANDLER);

我注册了一个关闭NettyServer的ShutdownHook,如下所示:

boundChannel.close().await(5000);
bossGroup.shutdownGracefully(0, 10, TimeUnit.SECONDS);
workerGroup.shutdownGracefully(0, 10, TimeUnit.SECONDS);
bossGroup.terminationFuture().awaitUninterruptibly(10, TimeUnit.SECONDS);
workerGroup.terminationFuture().awaitUninterruptibly(10, TimeUnit.SECONDS);
SHARED_EVENT_EXECUTOR.shutdownGracefully(0, 10, TimeUnit.SECONDS);
SHARED_EVENT_EXECUTOR.terminationFuture().awaitUninterruptibly(10, TimeUnit.SECONDS);

当我连接客户端时,会抛出 RejectedExecutionException

java.util.concurrent.RejectedExecutionException: event executor terminated
    at io.netty.util.concurrent.SingleThreadEventExecutor.reject(SingleThreadEventExecutor.java:703) [netty-all-4.0.13.Final.jar:4.0.13.Final]
    at io.netty.util.concurrent.SingleThreadEventExecutor.addTask(SingleThreadEventExecutor.java:296) [netty-all-4.0.13.Final.jar:4.0.13.Final]
    at io.netty.util.concurrent.SingleThreadEventExecutor.execute(SingleThreadEventExecutor.java:691) [netty-all-4.0.13.Final.jar:4.0.13.Final]
    at io.netty.channel.DefaultChannelHandlerContext.teardown(DefaultChannelHandlerContext.java:91) ~[netty-all-4.0.13.Final.jar:4.0.13.Final]
    at io.netty.channel.DefaultChannelHandlerContext.teardown0(DefaultChannelHandlerContext.java:106) ~[netty-all-4.0.13.Final.jar:4.0.13.Final]
    at io.netty.channel.DefaultChannelHandlerContext.access$000(DefaultChannelHandlerContext.java:29) ~[netty-all-4.0.13.Final.jar:4.0.13.Final]
    at io.netty.channel.DefaultChannelHandlerContext$1.run(DefaultChannelHandlerContext.java:94) ~[netty-all-4.0.13.Final.jar:4.0.13.Final]
    at io.netty.util.concurrent.SingleThreadEventExecutor.runAllTasks(SingleThreadEventExecutor.java:325) [netty-all-4.0.13.Final.jar:4.0.13.Final]
    at io.netty.util.concurrent.SingleThreadEventExecutor.confirmShutdown(SingleThreadEventExecutor.java:613) [netty-all-4.0.13.Final.jar:4.0.13.Final]
    at io.netty.util.concurrent.DefaultEventExecutor.run(DefaultEventExecutor.java:40) [netty-all-4.0.13.Final.jar:4.0.13.Final]
    at io.netty.util.concurrent.SingleThreadEventExecutor$2.run(SingleThreadEventExecutor.java:101) [netty-all-4.0.13.Final.jar:4.0.13.Final]
    at java.lang.Thread.run(Thread.java:744) [na:1.7.0_45]

根据应用程序关闭的netty4文档也没有帮助。我是否必须按照特定的顺序关闭我的申请?

我想要达到的目标是:  1.停止接受传入的消息  2.处理所有排队的消息,这可能涉及发送消息

1 个答案:

答案 0 :(得分:0)

当你调用shutdown时,如果有任何线程将任务放入taskQueue,并且taskQueue不为空,它将调用reject()方法来拒绝你的put动作。