1
votes

I have a problem with a web app running on a tomcat7.

When I try to restart the web app, the port opened by a thread I create inside a servlet is still open.

Only finding and killing the java process helps.

I get this error message in the tomcat log:

SEVERE: The web application [/mdm-server-1.0.0] appears to have started a thread named [com.google.inject.internal.util.$Finalizer] but has failed to stop it. This is very likely to create a memory leak. Nov 26, 2014 1:24:50 PM org.apache.catalina.loader.WebappClassLoader clearReferencesThreads SEVERE: The web application [/mdm-server-1.0.0] appears to have started a thread named [Thread-3] but has failed to stop it. This is very likely to create a memory leak.

The message seems to lead to a guice problem. I have a Servlet that is supposed to wait for client connections. When the application is re-deployed, the socket remains in use and the java thread survives. May it be that the thread holding the socket cannot be stopped since a depencendy, like the guice finalizer, cannot be terminated? Or am I totally on the wrong road there? The class and its dependencies do not use guice but are part of a webapp.

Here is a jstack output, maybe that helps:

"http-bio-8080-AsyncTimeout" daemon prio=10 tid=0x00007f4ed42e2800 nid=0x71f1 waiting on condition [0x00007f4ecc68e000]
java.lang.Thread.State: TIMED_WAITING (sleeping) at java.lang.Thread.sleep(Native Method) at org.apache.tomcat.util.net.JIoEndpoint$AsyncTimeout.run(JIoEndpoint.java:148) at java.lang.Thread.run(Thread.java:745)

"http-bio-8080-Acceptor-0" daemon 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) at java.net.ServerSocket.accept(ServerSocket.java:498) at org.apache.tomcat.util.net.DefaultServerSocketFactory.acceptSocket(DefaultServerSocketFactory.java:60) at org.apache.tomcat.util.net.JIoEndpoint$Acceptor.run(JIoEndpoint.java:216) at java.lang.Thread.run(Thread.java:745)

"ContainerBackgroundProcessor[StandardEngine[Tomcat]]" daemon prio=10 tid=0x00007f4ed4205800 nid=0x71ef waiting on condition [0x00007f4ecc890000] java.lang.Thread.State: TIMED_WAITING (sleeping) at java.lang.Thread.sleep(Native Method) at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.run(ContainerBase.java:1508) at java.lang.Thread.run(Thread.java:745)

"Thread-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) at java.net.ServerSocket.accept(ServerSocket.java:498) at testproject.server.device.AcceptConnectionDaemon.run(AcceptConnectionDaemon.java:39) at java.lang.Thread.run(Thread.java:745)

"com.google.inject.internal.util.$Finalizer" daemon prio=10 tid=0x00007f4ea074d000 nid=0x71ed in Object.wait() [0x00007f4ecca92000] java.lang.Thread.State: WAITING (on object monitor) at java.lang.Object.wait(Native Method) - waiting on <0x00000007ea2a9a18> (a java.lang.ref.ReferenceQueue$Lock) at java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:135) - locked <0x00000007ea2a9a18> (a java.lang.ref.ReferenceQueue$Lock) at java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:151) at com.google.inject.internal.util.$Finalizer.run(Finalizer.java:114)

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

"pool-1-thread-5" prio=10 tid=0x00007f4ed42fa000 nid=0x71e9 waiting on condition [0x00007f4ecd41b000] java.lang.Thread.State: WAITING (parking) at sun.misc.Unsafe.park(Native Method) - parking to wait for <0x0000000785ed5558> (a java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject) at java.util.concurrent.locks.LockSupport.park(LockSupport.java:186) at java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.await(AbstractQueuedSynchronizer.java:2043) at java.util.concurrent.LinkedBlockingQueue.take(LinkedBlockingQueue.java:442) at java.util.concurrent.ThreadPoolExecutor.getTask(ThreadPoolExecutor.java:1068) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1130) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) at java.lang.Thread.run(Thread.java:745)

"pool-1-thread-4" prio=10 tid=0x00007f4ed4288800 nid=0x71e8 waiting on condition [0x00007f4ecd51c000] java.lang.Thread.State: WAITING (parking) at sun.misc.Unsafe.park(Native Method) - parking to wait for <0x0000000785ed5558> (a java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject) at java.util.concurrent.locks.LockSupport.park(LockSupport.java:186) at java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.await(AbstractQueuedSynchronizer.java:2043) at java.util.concurrent.LinkedBlockingQueue.take(LinkedBlockingQueue.java:442) at java.util.concurrent.ThreadPoolExecutor.getTask(ThreadPoolExecutor.java:1068) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1130) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) at java.lang.Thread.run(Thread.java:745)

"pool-1-thread-3" prio=10 tid=0x00007f4e90001800 nid=0x71e7 waiting on condition [0x00007f4ecd61d000] java.lang.Thread.State: WAITING (parking) at sun.misc.Unsafe.park(Native Method) - parking to wait for <0x0000000785ed5558> (a java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject) at java.util.concurrent.locks.LockSupport.park(LockSupport.java:186) at java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.await(AbstractQueuedSynchronizer.java:2043) at java.util.concurrent.LinkedBlockingQueue.take(LinkedBlockingQueue.java:442) at java.util.concurrent.ThreadPoolExecutor.getTask(ThreadPoolExecutor.java:1068) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1130) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) at java.lang.Thread.run(Thread.java:745)

"pool-1-thread-2" prio=10 tid=0x00007f4ed42de800 nid=0x71e6 waiting on condition [0x00007f4ecd71e000] java.lang.Thread.State: WAITING (parking) at sun.misc.Unsafe.park(Native Method) - parking to wait for <0x0000000785ed5558> (a java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject) at java.util.concurrent.locks.LockSupport.park(LockSupport.java:186) at java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.await(AbstractQueuedSynchronizer.java:2043) at java.util.concurrent.LinkedBlockingQueue.take(LinkedBlockingQueue.java:442) at java.util.concurrent.ThreadPoolExecutor.getTask(ThreadPoolExecutor.java:1068) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1130) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) at java.lang.Thread.run(Thread.java:745)

"pool-1-thread-1" prio=10 tid=0x00007f4ed42dd800 nid=0x71e5 waiting on condition [0x00007f4ecd81f000] java.lang.Thread.State: WAITING (parking) at sun.misc.Unsafe.park(Native Method) - parking to wait for <0x0000000785ed5558> (a java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject) at java.util.concurrent.locks.LockSupport.park(LockSupport.java:186) at java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.await(AbstractQueuedSynchronizer.java:2043) at java.util.concurrent.LinkedBlockingQueue.take(LinkedBlockingQueue.java:442) at java.util.concurrent.ThreadPoolExecutor.getTask(ThreadPoolExecutor.java:1068) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1130) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) at java.lang.Thread.run(Thread.java:745)

"Service Thread" daemon prio=10 tid=0x00007f4ed40a7000 nid=0x71e1 runnable [0x0000000000000000] java.lang.Thread.State: RUNNABLE

"C2 CompilerThread1" daemon prio=10 tid=0x00007f4ed40a4800 nid=0x71e0 waiting on condition [0x0000000000000000] java.lang.Thread.State: RUNNABLE

"C2 CompilerThread0" daemon prio=10 tid=0x00007f4ed40a2000 nid=0x71df waiting on condition [0x0000000000000000] java.lang.Thread.State: RUNNABLE

"JDWP Event Helper Thread" daemon prio=10 tid=0x00007f4ed409f800 nid=0x71de runnable [0x0000000000000000] java.lang.Thread.State: RUNNABLE

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

"Signal Dispatcher" daemon prio=10 tid=0x00007f4ed408f000 nid=0x71dc waiting on condition [0x0000000000000000] java.lang.Thread.State: RUNNABLE

"Finalizer" daemon prio=10 tid=0x00007f4ed406e800 nid=0x71db in Object.wait() [0x00007f4ece6b5000] java.lang.Thread.State: WAITING (on object monitor) at java.lang.Object.wait(Native Method) - waiting on <0x0000000784ccd218> (a java.lang.ref.ReferenceQueue$Lock) at java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:135) - locked <0x0000000784ccd218> (a java.lang.ref.ReferenceQueue$Lock) at java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:151) at java.lang.ref.Finalizer$FinalizerThread.run(Finalizer.java:209)

"Reference Handler" daemon prio=10 tid=0x00007f4ed406c800 nid=0x71da in Object.wait() [0x00007f4ece7b6000] java.lang.Thread.State: WAITING (on object monitor) at java.lang.Object.wait(Native Method) - waiting on <0x0000000784cccd80> (a java.lang.ref.Reference$Lock) at java.lang.Object.wait(Object.java:503) at java.lang.ref.Reference$ReferenceHandler.run(Reference.java:133) - locked <0x0000000784cccd80> (a java.lang.ref.Reference$Lock)

"main" prio=10 tid=0x00007f4ed400d000 nid=0x71d6 in Object.wait() [0x00007f4edacd6000] java.lang.Thread.State: WAITING (on object monitor) at java.lang.Object.wait(Native Method) - waiting on <0x00000007eb7da230> (a java.lang.Object) at java.lang.Object.wait(Object.java:503) at org.apache.tomcat.maven.plugin.tomcat7.run.AbstractRunMojo.waitIndefinitely(AbstractRunMojo.java:1357) - locked <0x00000007eb7da230> (a java.lang.Object) at org.apache.tomcat.maven.plugin.tomcat7.run.AbstractRunMojo.execute(AbstractRunMojo.java:595) at org.apache.maven.plugin.DefaultPluginManager.executeMojo(DefaultPluginManager.java:490) at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoals(DefaultLifecycleExecutor.java:694) at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeStandaloneGoal(DefaultLifecycleExecutor.java:569) at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoal(DefaultLifecycleExecutor.java:539) at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoalAndHandleFailures(DefaultLifecycleExecutor.java:387) at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeTaskSegments(DefaultLifecycleExecutor.java:348) at org.apache.maven.lifecycle.DefaultLifecycleExecutor.execute(DefaultLifecycleExecutor.java:180) at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:328) at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:138) at org.apache.maven.cli.MavenCli.main(MavenCli.java:362) at 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) at org.codehaus.classworlds.Launcher.launchEnhanced(Launcher.java:315) at org.codehaus.classworlds.Launcher.launch(Launcher.java:255) at org.codehaus.classworlds.Launcher.mainWithExitCode(Launcher.java:430) at org.codehaus.classworlds.Launcher.main(Launcher.java:375)

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

I would be grateful for any help.

1

1 Answers

1
votes

Try checking Thread.isInterrupted() in the main loop of your Daemon class. Break the loop if it's true and it should allow Tomcat to shutdown your threads successfully.