我正在使用Netty 4.0.26.Final和Tomcat 8一起在Web應用程序內實現嵌入式TCP服務器。在tomcat中導致內存泄露的Netty
的問題是,當我停止Tomcat我得到這個消息:
The web application [app] appears to have started a thread named
[nioEventLoopGroup-2-1] but has failed to stop it. This is very likely to create a memory leak. Stack trace of thread:
sun.nio.ch.WindowsSelectorImpl$SubSelector.poll0(Native Method)
sun.nio.ch.WindowsSelectorImpl$SubSelector.poll(WindowsSelectorImpl.java:296)
sun.nio.ch.WindowsSelectorImpl$SubSelector.access$400(WindowsSelectorImpl.java:278)
sun.nio.ch.WindowsSelectorImpl.doSelect(WindowsSelectorImpl.java:159)
sun.nio.ch.SelectorImpl.lockAndDoSelect(SelectorImpl.java:87)
sun.nio.ch.SelectorImpl.select(SelectorImpl.java:98)
io.netty.channel.nio.NioEventLoop.select(NioEventLoop.java:622)
io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:310)
io.netty.util.concurrent.SingleThreadEventExecutor$2.run(SingleThreadEventExecutor.java:111)
io.netty.util.concurrent.DefaultThreadFactory$DefaultRunnableDecorator.run(DefaultThreadFactory.java:137)
我已經使用這個類關機關閉Tomcat的前線程嘗試,但我仍然有同樣的問題。
@Component
public class MyAppServletContextListener implements ServletContextListener{
@Override
public void contextInitialized(ServletContextEvent arg0) {
}
@Override
public void contextDestroyed(ServletContextEvent arg0) {
TrackingDaemon trackingDaemon= (TrackingDaemon) ApplicationContextProvider.getBean("trackingDaemon");
trackingDaemon.bossGroup.shutdownGracefully();
trackingDaemon.workerGroup.shutdownGracefully();
}
}
BossGroup和workerGroup是:
EventLoopGroup bossGroup = new NioEventLoopGroup();
EventLoopGroup workerGroup = new NioEventLoopGroup();
任何幫助將不勝感激..