【问题标题】:Android - Netty - RejectedExecutionExceptionAndroid - Netty - RejectedExecutionException
【发布时间】:2025-12-01 19:20:08
【问题描述】:

我带着一个棘手的问题回来了。

我已经为我们的 Android 项目编写了一个 netty 服务器,但有时,当我尝试向连接的客户端发送一些东西时,我得到了一个 RejectedExecutionException。

03-17 22:07:49.938 21708-22346/htlhallein.at.serverdatenbrille_rewritten E/AndroidRuntime: 致命异常: Thread-9824 进程:htlhallein.at.serverdatenbrille_rewritten,PID:21708 java.util.concurrent.RejectedExecutionException:事件执行器终止 在 io.netty.util.concurrent.SingleThreadEventExecutor.reject(SingleThreadEventExecutor.java:707) 在 io.netty.util.concurrent.SingleThreadEventExecutor.addTask(SingleThreadEventExecutor.java:299) 在 io.netty.util.concurrent.SingleThreadEventExecutor.execute(SingleThreadEventExecutor.java:690) 在 io.netty.channel.AbstractChannel$AbstractUnsafe.register(AbstractChannel.java:421) 在 io.netty.channel.SingleThreadEventLoop.register(SingleThreadEventLoop.java:60) 在 io.netty.channel.SingleThreadEventLoop.register(SingleThreadEventLoop.java:48) 在 io.netty.channel.MultithreadEventLoopGroup.register(MultithreadEventLoopGroup.java:64) 在 io.netty.bootstrap.AbstractBootstrap.initAndRegister(AbstractBootstrap.java:315) 在 io.netty.bootstrap.AbstractBootstrap.doBind(AbstractBootstrap.java:271) 在 io.netty.bootstrap.AbstractBootstrap.bind(AbstractBootstrap.java:267) 在 io.netty.bootstrap.AbstractBootstrap.bind(AbstractBootstrap.java:242) 在 htlhallein.at.serverdatenbrille_rewritten.server.DatenbrillenServer$Server.run(DatenbrillenServer.java:172) 在 java.lang.Thread.run(Thread.java:841)

我不确定我应该使用哪个 Event Executor? 运行服务器后,异常被触发一行。 (Log.d(DatenbrillenServer.class.toString(), "Stopped Server ...");)

有没有人有想法,为什么会这样?

非常感谢!

【问题讨论】:

    标签: netty nio


    【解决方案1】:

    当您在调用 shutdownGracefully() 后尝试执行 IO 时会发生这种情况。在调用它之前确保你完成了所有的 IO

    【讨论】:

    • 谢谢你!我也使用了 4.0.26 Final,但是您在 4.1+ 版本中添加了官方的 Android 支持,并且我将 server.stop() 从 android stop 事件移动到了 destroy 事件。现在它就像一个魅力!