2017-04-01 68 views
0

我已經習慣了下面的代碼來處理服務器關機:的Netty服務器關閉異常

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); 
     } 
    } 

有時服務器shutsdown以下情況例外:

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 

我使用的網狀版本4.1.9。最終在JVM版本:

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

請幫我在這裏找出問題。讓我知道是否需要其他細節。

+0

你在你的pom依賴中使用netty-all嗎? – nllsdfx

+0

關閉服務器時,該jar是否仍然加載?一些jar部署系統在關閉服務器之前替換jar文件。如果你有一個系統,在寫一個新文件之前刪除這個文件,因爲在Linux上這意味着舊文件仍然正常加載 – Ferrybig

+0

@DmitrySoroka我已經在pom依賴文件中包含了netty-all – sshntt

回答

1

這很可能是因爲在關閉100%完成之前卸載了jar。 .shutdownGracefully(...)是異步的,所以你應該在這裏使用.shutdownGracefully(...).sync()