java - Netty服务器关闭异常

标签 java netty tcpserver

我习惯使用以下代码来处理服务器关闭:

public void stop() {
    try {
        this.channelFuture.channel().close();
        this.channelFuture.channel().closeFuture().sync();
    } catch (InterruptedException e) {
        Log.exceptionStack(e);
    } finally {
        this.bootstrap.config().childGroup().shutdownGracefully(10, 30, TimeUnit.SECONDS);
        this.bootstrap.config().group().shutdownGracefully(5, 10, TimeUnit.SECONDS);
    }
}

有时服务器会因以下异常而关闭:

Exception in thread "nioEventLoopGroup-3-1" java.lang.NoClassDefFoundError: io/netty/buffer/PoolArena$1
        at io.netty.buffer.PoolArena.freeChunk(PoolArena.java:293)
        at io.netty.buffer.PoolThreadCache$MemoryRegionCache.freeEntry(PoolThreadCache.java:471)
        at io.netty.buffer.PoolThreadCache$MemoryRegionCache.free(PoolThreadCache.java:441)
        at io.netty.buffer.PoolThreadCache$MemoryRegionCache.free(PoolThreadCache.java:433)
        at io.netty.buffer.PoolThreadCache.free(PoolThreadCache.java:290)
        at io.netty.buffer.PoolThreadCache.free(PoolThreadCache.java:281)
        at io.netty.buffer.PoolThreadCache.free0(PoolThreadCache.java:254)
        at io.netty.buffer.PoolThreadCache.free(PoolThreadCache.java:250)
        at io.netty.buffer.PooledByteBufAllocator$PoolThreadLocalCache.onRemoval(PooledByteBufAllocator.java:431)
        at io.netty.buffer.PooledByteBufAllocator$PoolThreadLocalCache.onRemoval(PooledByteBufAllocator.java:408)
        at io.netty.util.concurrent.FastThreadLocal.remove(FastThreadLocal.java:226)
        at io.netty.util.concurrent.FastThreadLocal.removeAll(FastThreadLocal.java:67)
        at io.netty.util.concurrent.DefaultThreadFactory$DefaultRunnableDecorator.run(DefaultThreadFactory.java:146)
        at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.ClassNotFoundException: io.netty.buffer.PoolArena$1
        at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
        at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
        ... 14 more
Exception in thread "Thread-1" java.lang.NoClassDefFoundError: io/netty/channel/AbstractChannelHandlerContext$13
        at io.netty.channel.AbstractChannelHandlerContext.close(AbstractChannelHandlerContext.java:610)
        at io.netty.channel.AbstractChannelHandlerContext.close(AbstractChannelHandlerContext.java:465)
        at io.netty.channel.DefaultChannelPipeline.close(DefaultChannelPipeline.java:964)
        at io.netty.channel.AbstractChannel.close(AbstractChannel.java:234)
        at co.gps.smaartly.TrackerServer.stop(TrackerServer.java:59)
        at co.gps.smaartly.ServerManager.stop(ServerManager.java:90)
        at co.gps.smaartly.App$1.run(App.java:22)
Caused by: java.lang.ClassNotFoundException: io.netty.channel.AbstractChannelHandlerContext$13
        at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
        at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
        ... 7 more

我在 JVM 版本上使用 netty 版本 4.1.9.Final:

java version "1.8.0_121"
Java(TM) SE Runtime Environment (build 1.8.0_121-b13)
Java HotSpot(TM) 64-Bit Server VM (build 25.121-b13, mixed mode)

在 Ubuntu 16.04 上

请帮我找出问题所在。如果需要任何其他详细信息,请告诉我。

最佳答案

这很可能是因为 jar 在关闭 100% 完成之前被卸载。 .shutdownGraceously(...) 是异步的,因此您应该在此处使用 .shutdownGraceously(...).sync()

关于java - Netty服务器关闭异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43157430/

相关文章:

java - 使用 Intent 启动新的 Activity。 NPE 位于 android.content.ContextWrapper.getPackageName

java - Spring - 访问Advice中注释的参数

c++ - 套接字服务器以缓冲区大小接收数据

java - Netty 是否违反了 Future.cancel(...) 方法的约定?

java - 如何管理netty中发送数据的客户端列表

c++ - 段错误 - 通过服务器将对象发送到客户端

c# - TCP ZeroWindow 问题 C#

java - 如何将不同的主题应用到桌面 swing 软件?

java - StackOverflow 错误,View.inflate 异常

java - 已收到消息未调用