tomcat7 servlet中的内存泄漏

时间:2014-11-26 12:45:21

标签: java tomcat servlets memory-leaks

我在tomcat7上运行的网络应用有问题。

当我尝试重新启动Web应用程序时,我在servlet中创建的线程打开的端口仍处于打开状态。

只有找到并杀死java进程才有帮助。

我在tomcat日志中收到此错误消息:

  

严重:Web应用程序[/mdm-server-1.0.0]似乎有   启动了一个名为[com.google.inject.internal.util。$ Finalizer]的线程   但未能阻止它。这很可能会创建一个内存   泄漏。 2014年11月26日下午1:24:50   org.apache.catalina.loader.WebappClassLoader clearReferencesThreads   严重:Web应用程序[/mdm-server-1.0.0]似乎有   启动了一个名为[Thread-3]的线程但未能阻止它。这是   很可能会造成内存泄漏。

该消息似乎导致了一个问题。我有一个应该等待客户端连接的Servlet。重新部署应用程序时,套接字仍在使用中,并且java线程仍然存在。 可能是持有套接字的线程无法停止,因为像guice终结器这样的依赖不能终止?还是我完全走错了路?该类及其依赖项不使用guice,但是是webapp的一部分。

这是一个jstack输出,可能有帮助:

  

" HTTP的生物8080-AsyncTimeout"守护进程prio = 10 tid = 0x00007f4ed42e2800   nid = 0x71f1等待条件[0x00007f4ecc68e000]
  java.lang.Thread.State:TIMED_WAITING(休眠)       at java.lang.Thread.sleep(Native Method)       at org.apache.tomcat.util.net.JIoEndpoint $ AsyncTimeout.run(JIoEndpoint.java:148)       在java.lang.Thread.run(Thread.java:745)

     

" HTTP的生物8080-接受器 - 0"守护进程prio = 10 tid = 0x00007f4ed4206000   nid = 0x71f0 runnable [0x00007f4ecc78f000] java.lang.Thread.State:   RUNNABLE       at java.net.PlainSocketImpl.socketAccept(Native Method)       at java.net.AbstractPlainSocketImpl.accept(AbstractPlainSocketImpl.java:398)       at java.net.ServerSocket.implAccept(ServerSocket.java:530)       在java.net.ServerSocket.accept(ServerSocket.java:498)       在org.apache.tomcat.util.net.DefaultServerSocketFactory.acceptSocket(DefaultServerSocketFactory.java:60)       at org.apache.tomcat.util.net.JIoEndpoint $ Acceptor.run(JIoEndpoint.java:216)       在java.lang.Thread.run(Thread.java:745)

     

" ContainerBackgroundProcessor [StandardEngine [Tomcat的]"守护进程prio = 10   tid = 0x00007f4ed4205800 nid = 0x71ef等待条件   [0x00007f4ecc890000] java.lang.Thread.State:TIMED_WAITING   (睡眠)       at java.lang.Thread.sleep(Native Method)       在org.apache.catalina.core.ContainerBase $ ContainerBackgroundProcessor.run(ContainerBase.java:1508)       在java.lang.Thread.run(Thread.java:745)

     

"螺纹-4" daemon prio = 10 tid = 0x00007f4ea00f6800 nid = 0x71ee runnable   [0x00007f4ecc991000] java.lang.Thread.State:RUNNABLE       at java.net.PlainSocketImpl.socketAccept(Native Method)       at java.net.AbstractPlainSocketImpl.accept(AbstractPlainSocketImpl.java:398)       at java.net.ServerSocket.implAccept(ServerSocket.java:530)       在java.net.ServerSocket.accept(ServerSocket.java:498)       at testproject.server.device.AcceptConnectionDaemon.run(AcceptConnectionDaemon.java:39)       在java.lang.Thread.run(Thread.java:745)

     

" com.google.inject.internal.util $终结"守护进程prio = 10   Object.wait()中的tid = 0x00007f4ea074d000 nid = 0x71ed   [0x00007f4ecca92000] java.lang.Thread.State:WAITING(在对象上   监控)       at java.lang.Object.wait(Native Method)        - 等待< 0x00000007ea2a9a18> (java.lang.ref.ReferenceQueue $ Lock)       at java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:135)        - 已锁定< 0x00000007ea2a9a18> (java.lang.ref.ReferenceQueue $ Lock)       at java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:151)       在com.google.inject.internal.util。$ Finalizer.run(Finalizer.java:114)

     

"螺纹-3" daemon prio = 10 tid = 0x00007f4ea1a71800 nid = 0x71ec runnable   [0x00007f4eccb93000] java.lang.Thread.State:RUNNABLE       在sun.nio.ch.EPoll.epollWait(原生方法)       at sun.nio.ch.EPollPort $ EventHandlerTask.poll(EPollPort.java:194)       at sun.nio.ch.EPollPort $ EventHandlerTask.run(EPollPort.java:268)       在java.lang.Thread.run(Thread.java:745)

     

"池-1-线程5" prio = 10 tid = 0x00007f4ed42fa000 nid = 0x71e9等待   condition [0x00007f4ecd41b000] java.lang.Thread.State:WAITING   (停车处)       在sun.misc.Unsafe.park(原生方法)        - 停车等待< 0x0000000785ed5558> (java.util.concurrent.locks.AbstractQueuedSynchronizer $ ConditionObject)       在java.util.concurrent.locks.LockSupport.park(LockSupport.java:186)       at java.util.concurrent.locks.AbstractQueuedSynchronizer $ ConditionObject.await(AbstractQueuedSynchronizer.java:2043)       在java.util.concurrent.LinkedBlockingQueue.take(LinkedBlockingQueue.java:442)       at java.util.concurrent.ThreadPoolExecutor.getTask(ThreadPoolExecutor.java:1068)       在java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1130)       at java.util.concurrent.ThreadPoolExecutor $ Worker.run(ThreadPoolExecutor.java:615)       在java.lang.Thread.run(Thread.java:745)

     

"池-1-螺纹-4" prio = 10 tid = 0x00007f4ed4288800 nid = 0x71e8等待   condition [0x00007f4ecd51c000] java.lang.Thread.State:WAITING   (停车处)       在sun.misc.Unsafe.park(原生方法)        - 停车等待< 0x0000000785ed5558> (java.util.concurrent.locks.AbstractQueuedSynchronizer $ ConditionObject)       在java.util.concurrent.locks.LockSupport.park(LockSupport.java:186)       at java.util.concurrent.locks.AbstractQueuedSynchronizer $ ConditionObject.await(AbstractQueuedSynchronizer.java:2043)       在java.util.concurrent.LinkedBlockingQueue.take(LinkedBlockingQueue.java:442)       at java.util.concurrent.ThreadPoolExecutor.getTask(ThreadPoolExecutor.java:1068)       在java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1130)       at java.util.concurrent.ThreadPoolExecutor $ Worker.run(ThreadPoolExecutor.java:615)       在java.lang.Thread.run(Thread.java:745)

     

"池-1-螺纹-3" prio = 10 tid = 0x00007f4e90001800 nid = 0x71e7等待   condition [0x00007f4ecd61d000] java.lang.Thread.State:WAITING   (停车处)       在sun.misc.Unsafe.park(原生方法)        - 停车等待< 0x0000000785ed5558> (java.util.concurrent.locks.AbstractQueuedSynchronizer $ ConditionObject)       在java.util.concurrent.locks.LockSupport.park(LockSupport.java:186)       at java.util.concurrent.locks.AbstractQueuedSynchronizer $ ConditionObject.await(AbstractQueuedSynchronizer.java:2043)       在java.util.concurrent.LinkedBlockingQueue.take(LinkedBlockingQueue.java:442)       at java.util.concurrent.ThreadPoolExecutor.getTask(ThreadPoolExecutor.java:1068)       在java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1130)       at java.util.concurrent.ThreadPoolExecutor $ Worker.run(ThreadPoolExecutor.java:615)       在java.lang.Thread.run(Thread.java:745)

     

"池-1-螺纹-2" prio = 10 tid = 0x00007f4ed42de800 nid = 0x71e6等待   condition [0x00007f4ecd71e000] java.lang.Thread.State:WAITING   (停车处)       在sun.misc.Unsafe.park(原生方法)        - 停车等待< 0x0000000785ed5558> (java.util.concurrent.locks.AbstractQueuedSynchronizer $ ConditionObject)       在java.util.concurrent.locks.LockSupport.park(LockSupport.java:186)       at java.util.concurrent.locks.AbstractQueuedSynchronizer $ ConditionObject.await(AbstractQueuedSynchronizer.java:2043)       在java.util.concurrent.LinkedBlockingQueue.take(LinkedBlockingQueue.java:442)       at java.util.concurrent.ThreadPoolExecutor.getTask(ThreadPoolExecutor.java:1068)       在java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1130)       at java.util.concurrent.ThreadPoolExecutor $ Worker.run(ThreadPoolExecutor.java:615)       在java.lang.Thread.run(Thread.java:745)

     

"池-1-线程1" prio = 10 tid = 0x00007f4ed42dd800 nid = 0x71e5等待   condition [0x00007f4ecd81f000] java.lang.Thread.State:WAITING   (停车处)       在sun.misc.Unsafe.park(原生方法)        - 停车等待< 0x0000000785ed5558> (java.util.concurrent.locks.AbstractQueuedSynchronizer $ ConditionObject)       在java.util.concurrent.locks.LockSupport.park(LockSupport.java:186)       at java.util.concurrent.locks.AbstractQueuedSynchronizer $ ConditionObject.await(AbstractQueuedSynchronizer.java:2043)       在java.util.concurrent.LinkedBlockingQueue.take(LinkedBlockingQueue.java:442)       at java.util.concurrent.ThreadPoolExecutor.getTask(ThreadPoolExecutor.java:1068)       在java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1130)       at java.util.concurrent.ThreadPoolExecutor $ Worker.run(ThreadPoolExecutor.java:615)       在java.lang.Thread.run(Thread.java:745)

     

"服务主题"守护进程prio = 10 tid = 0x00007f4ed40a7000 nid = 0x71e1   runnable [0x0000000000000000] java.lang.Thread.State:RUNNABLE

     

" C2 CompilerThread1"守护进程prio = 10 tid = 0x00007f4ed40a4800 nid = 0x71e0   等待条件[0x0000000000000000] java.lang.Thread.State:   RUNNABLE

     

" C2 CompilerThread0"守护进程prio = 10 tid = 0x00007f4ed40a2000 nid = 0x71df   等待条件[0x0000000000000000] java.lang.Thread.State:   RUNNABLE

     

" JDWP事件助手线程"守护进程prio = 10 tid = 0x00007f4ed409f800   nid = 0x71de runnable [0x0000000000000000] java.lang.Thread.State:   RUNNABLE

     

" JDWP Transport Listener:dt_socket"守护进程prio = 10   tid = 0x00007f4ed409c000 nid = 0x71dd runnable [0x0000000000000000]
  java.lang.Thread.State:RUNNABLE

     

" Signal Dispatcher"守护进程prio = 10 tid = 0x00007f4ed408f000 nid = 0x71dc   等待条件[0x0000000000000000] java.lang.Thread.State:   RUNNABLE

     

"终结"守护进程prio = 10 tid = 0x00007f4ed406e800 nid = 0x71db in   Object.wait()[0x00007f4ece6b5000] java.lang.Thread.State:WAITING   (在对象监视器上)       at java.lang.Object.wait(Native Method)        - 等待< 0x0000000784ccd218> (java.lang.ref.ReferenceQueue $ Lock)       at java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:135)        - 已锁定< 0x0000000784ccd218> (java.lang.ref.ReferenceQueue $ Lock)       at java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:151)       在java.lang.ref.Finalizer $ FinalizerThread.run(Finalizer.java:209)

     

"参考处理程序"守护进程prio = 10 tid = 0x00007f4ed406c800 nid = 0x71da   在Object.wait()[0x00007f4ece7b6000]中java.lang.Thread.State:   等待(在对象监视器上)       at java.lang.Object.wait(Native Method)        - 等待< 0x0000000784cccd80> (java.lang.ref.Reference $ Lock)       在java.lang.Object.wait(Object.java:503)       at java.lang.ref.Reference $ ReferenceHandler.run(Reference.java:133)        - 已锁定< 0x0000000784cccd80> (java.lang.ref.Reference $ Lock)

     

"主" Object.wait()中的prio = 10 tid = 0x00007f4ed400d000 nid = 0x71d6   [0x00007f4edacd6000] java.lang.Thread.State:WAITING(在对象上   监控)       at java.lang.Object.wait(Native Method)        - 等待< 0x00000007eb7da230> (一个java.lang.Object)       在java.lang.Object.wait(Object.java:503)       在org.apache.tomcat.maven.plugin.tomcat7.run.AbstractRunMojo.waitIndefinitely(AbstractRunMojo.java:1357)        - 已锁定< 0x00000007eb7da230> (一个java.lang.Object)       在org.apache.tomcat.maven.plugin.tomcat7.run.AbstractRunMojo.execute(AbstractRunMojo.java:595)       在org.apache.maven.plugin.DefaultPluginManager.executeMojo(DefaultPluginManager.java:490)       at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoals(DefaultLifecycleExecutor.java:694)       在org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeStandaloneGoal(DefaultLifecycleExecutor.java:569)       在org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoal(DefaultLifecycleExecutor.java:539)       在org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoalAndHandleFailures(DefaultLifecycleExecutor.java:387)       在org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeTaskSegments(DefaultLifecycleExecutor.java:348)       在org.apache.maven.lifecycle.DefaultLifecycleExecutor.execute(DefaultLifecycleExecutor.java:180)       在org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:328)       在org.apache.maven.DefaultMaven.execute(DefaultMaven.java:138)       在org.apache.maven.cli.MavenCli.main(MavenCli.java:362)       在org.apache.maven.cli.compat.CompatibleMain.main(CompatibleMain.java:60)       at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)       at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)       at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)       at java.lang.reflect.Method.invoke(Method.java:606)       在org.codehaus.classworlds.Launcher.launchEnhanced(Launcher.java:315)       在org.codehaus.classworlds.Launcher.launch(Launcher.java:255)       在org.codehaus.classworlds.Launcher.mainWithExitCode(Launcher.java:430)       在org.codehaus.classworlds.Launcher.main(Launcher.java:375)

     

" VM Thread" prio = 10 tid = 0x00007f4ed4068800 nid = 0x71d9 runnable

如果有任何帮助,我将不胜感激。

1 个答案:

答案 0 :(得分:1)

尝试检查Daemon课程主循环中的Thread.isInterrupted()。如果它是真的则打破循环并且它应该允许Tomcat成功关闭你的线程。