Preliminary: I looked for similar questions on SO and the one most closely resembling mine is this: Unable to shut down neo4j jetty server within tomcat. I've tried all solutions proposed there but without success.
I'm running into a shutdown issue when running a Jersey application with embedded Neo4j database on Tomcat. Deploying (using Maven 3.3.9) works fine and the database is started, but on redeploy/undeploy, I get a Tomcat warning:
21-Feb-2017 17:37:10.242 WARNING [http-nio-8080-exec-6] org.apache.catalina.loader.WebappClassLoaderBase.clearReferencesThreads The web application [mytest] appears to have started a thread named [pool-17-thread-1] but has failed to stop it. This is very likely to create a memory leak. Stack trace of thread: sun.misc.Unsafe.park(Native Method) java.util.concurrent.locks.LockSupport.parkNanos(LockSupport.java:215) java.util.concurrent.SynchronousQueue$TransferStack.awaitFulfill(SynchronousQueue.java:460) java.util.concurrent.SynchronousQueue$TransferStack.transfer(SynchronousQueue.java:362) java.util.concurrent.SynchronousQueue.poll(SynchronousQueue.java:941) java.util.concurrent.ThreadPoolExecutor.getTask(ThreadPoolExecutor.java:1066) java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1127) java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) java.lang.Thread.run(Thread.java:745) 21-Feb-2017 17:37:10.242 SEVERE [http-nio-8080-exec-6] org.apache.catalina.loader.WebappClassLoaderBase.checkThreadLocalMapForLeaks The web application [mytest] created a ThreadLocal with key of type [org.neo4j.io.pagecache.impl.muninn.CursorPool] (value [org.neo4j.io.pagecache.impl.muninn.CursorPool@2c930a78]) and a value of type [org.neo4j.io.pagecache.impl.muninn.CursorPool.CursorSets] (value [org.neo4j.io.pagecache.impl.muninn.CursorPool$CursorSets@4c0b4554]) but failed to remove it when the web application was stopped. Threads are going to be renewed over time to try and avoid a probable memory leak. 21-Feb-2017 17:37:10.242 SEVERE [http-nio-8080-exec-6] org.apache.catalina.loader.WebappClassLoaderBase.checkThreadLocalMapForLeaks The web application [mytest] created a ThreadLocal with key of type [org.neo4j.io.pagecache.impl.muninn.CursorPool] (value [org.neo4j.io.pagecache.impl.muninn.CursorPool@1c3e6e38]) and a value of type [org.neo4j.io.pagecache.impl.muninn.CursorPool.CursorSets] (value [org.neo4j.io.pagecache.impl.muninn.CursorPool$CursorSets@3f71b23c]) but failed to remove it when the web application was stopped. Threads are going to be renewed over time to try and avoid a probable memory leak. 21-Feb-2017 17:37:10.242 SEVERE [http-nio-8080-exec-6] org.apache.catalina.loader.WebappClassLoaderBase.checkThreadLocalMapForLeaks The web application [mytest] created a ThreadLocal with key of type [org.neo4j.io.pagecache.impl.muninn.CursorPool] (value [org.neo4j.io.pagecache.impl.muninn.CursorPool@b05bf60]) and a value of type [org.neo4j.io.pagecache.impl.muninn.CursorPool.CursorSets] (value [org.neo4j.io.pagecache.impl.muninn.CursorPool$CursorSets@1d326ab1]) but failed to remove it when the web application was stopped. Threads are going to be renewed over time to try and avoid a probable memory leak. 21-Feb-2017 17:37:10.242 SEVERE [http-nio-8080-exec-6] org.apache.catalina.loader.WebappClassLoaderBase.checkThreadLocalMapForLeaks The web application [mytest] created a ThreadLocal with key of type [org.neo4j.io.pagecache.impl.muninn.CursorPool] (value [org.neo4j.io.pagecache.impl.muninn.CursorPool@72929881]) and a value of type [org.neo4j.io.pagecache.impl.muninn.CursorPool.CursorSets] (value [org.neo4j.io.pagecache.impl.muninn.CursorPool$CursorSets@40c024bd]) but failed to remove it when the web application was stopped. Threads are going to be renewed over time to try and avoid a probable memory leak. 21-Feb-2017 17:37:10.242 SEVERE [http-nio-8080-exec-6] org.apache.catalina.loader.WebappClassLoaderBase.checkThreadLocalMapForLeaks The web application [mytest] created a ThreadLocal with key of type [org.neo4j.io.pagecache.impl.muninn.CursorPool] (value [org.neo4j.io.pagecache.impl.muninn.CursorPool@66987d7a]) and a value of type [org.neo4j.io.pagecache.impl.muninn.CursorPool.CursorSets] (value [org.neo4j.io.pagecache.impl.muninn.CursorPool$CursorSets@68f1f4fa]) but failed to remove it when the web application was stopped. Threads are going to be renewed over time to try and avoid a probable memory leak. 21-Feb-2017 17:37:10.242 SEVERE [http-nio-8080-exec-6] org.apache.catalina.loader.WebappClassLoaderBase.checkThreadLocalMapForLeaks The web application [mytest] created a ThreadLocal with key of type [org.neo4j.io.pagecache.impl.muninn.CursorPool] (value [org.neo4j.io.pagecache.impl.muninn.CursorPool@e413ff5]) and a value of type [org.neo4j.io.pagecache.impl.muninn.CursorPool.CursorSets] (value [org.neo4j.io.pagecache.impl.muninn.CursorPool$CursorSets@4f65074c]) but failed to remove it when the web application was stopped. Threads are going to be renewed over time to try and avoid a probable memory leak. 21-Feb-2017 17:37:10.242 SEVERE [http-nio-8080-exec-6] org.apache.catalina.loader.WebappClassLoaderBase.checkThreadLocalMapForLeaks The web application [mytest] created a ThreadLocal with key of type [org.neo4j.io.pagecache.impl.muninn.CursorPool] (value [org.neo4j.io.pagecache.impl.muninn.CursorPool@6ab3d077]) and a value of type [org.neo4j.io.pagecache.impl.muninn.CursorPool.CursorSets] (value [org.neo4j.io.pagecache.impl.muninn.CursorPool$CursorSets@d02bfff]) but failed to remove it when the web application was stopped. Threads are going to be renewed over time to try and avoid a probable memory leak. 21-Feb-2017 17:37:10.242 SEVERE [http-nio-8080-exec-6] org.apache.catalina.loader.WebappClassLoaderBase.checkThreadLocalMapForLeaks The web application [mytest] created a ThreadLocal with key of type [org.neo4j.io.pagecache.impl.muninn.CursorPool] (value [org.neo4j.io.pagecache.impl.muninn.CursorPool@a3b973d]) and a value of type [org.neo4j.io.pagecache.impl.muninn.CursorPool.CursorSets] (value [org.neo4j.io.pagecache.impl.muninn.CursorPool$CursorSets@6d03be51]) but failed to remove it when the web application was stopped. Threads are going to be renewed over time to try and avoid a probable memory leak. 21-Feb-2017 17:37:10.243 SEVERE [http-nio-8080-exec-6] org.apache.catalina.loader.WebappClassLoaderBase.checkThreadLocalMapForLeaks The web application [mytest] created a ThreadLocal with key of type [org.neo4j.io.pagecache.impl.muninn.CursorPool] (value [org.neo4j.io.pagecache.impl.muninn.CursorPool@1947fbee]) and a value of type [org.neo4j.io.pagecache.impl.muninn.CursorPool.CursorSets] (value [org.neo4j.io.pagecache.impl.muninn.CursorPool$CursorSets@1a2527e]) but failed to remove it when the web application was stopped. Threads are going to be renewed over time to try and avoid a probable memory leak. 21-Feb-2017 17:37:10.243 SEVERE [http-nio-8080-exec-6] org.apache.catalina.loader.WebappClassLoaderBase.checkThreadLocalMapForLeaks The web application [mytest] created a ThreadLocal with key of type [org.neo4j.io.pagecache.impl.muninn.CursorPool] (value [org.neo4j.io.pagecache.impl.muninn.CursorPool@5776bf08]) and a value of type [org.neo4j.io.pagecache.impl.muninn.CursorPool.CursorSets] (value [org.neo4j.io.pagecache.impl.muninn.CursorPool$CursorSets@27776281]) but failed to remove it when the web application was stopped. Threads are going to be renewed over time to try and avoid a probable memory leak. 21-Feb-2017 17:37:10.243 SEVERE [http-nio-8080-exec-6] org.apache.catalina.loader.WebappClassLoaderBase.checkThreadLocalMapForLeaks The web application [mytest] created a ThreadLocal with key of type [org.neo4j.io.pagecache.impl.muninn.CursorPool] (value [org.neo4j.io.pagecache.impl.muninn.CursorPool@149750a]) and a value of type [org.neo4j.io.pagecache.impl.muninn.CursorPool.CursorSets] (value [org.neo4j.io.pagecache.impl.muninn.CursorPool$CursorSets@12ebf6ff]) but failed to remove it when the web application was stopped. Threads are going to be renewed over time to try and avoid a probable memory leak. 21-Feb-2017 17:37:10.243 SEVERE [http-nio-8080-exec-6] org.apache.catalina.loader.WebappClassLoaderBase.checkThreadLocalMapForLeaks The web application [mytest] created a ThreadLocal with key of type [org.neo4j.io.pagecache.impl.muninn.CursorPool] (value [org.neo4j.io.pagecache.impl.muninn.CursorPool@70078555]) and a value of type [org.neo4j.io.pagecache.impl.muninn.CursorPool.CursorSets] (value [org.neo4j.io.pagecache.impl.muninn.CursorPool$CursorSets@6cf882be]) but failed to remove it when the web application was stopped. Threads are going to be renewed over time to try and avoid a probable memory leak. 21-Feb-2017 17:37:10.243 SEVERE [http-nio-8080-exec-6] org.apache.catalina.loader.WebappClassLoaderBase.checkThreadLocalMapForLeaks The web application [mytest] created a ThreadLocal with key of type [org.neo4j.io.pagecache.impl.muninn.CursorPool] (value [org.neo4j.io.pagecache.impl.muninn.CursorPool@26d35b0e]) and a value of type [org.neo4j.io.pagecache.impl.muninn.CursorPool.CursorSets] (value [org.neo4j.io.pagecache.impl.muninn.CursorPool$CursorSets@6bc20d25]) but failed to remove it when the web application was stopped. Threads are going to be renewed over time to try and avoid a probable memory leak. 21-Feb-2017 17:37:10.243 SEVERE [http-nio-8080-exec-6] org.apache.catalina.loader.WebappClassLoaderBase.checkThreadLocalMapForLeaks The web application [mytest] created a ThreadLocal with key of type [org.neo4j.io.pagecache.impl.muninn.CursorPool] (value [org.neo4j.io.pagecache.impl.muninn.CursorPool@27a30025]) and a value of type [org.neo4j.io.pagecache.impl.muninn.CursorPool.CursorSets] (value [org.neo4j.io.pagecache.impl.muninn.CursorPool$CursorSets@f669b1d]) but failed to remove it when the web application was stopped. Threads are going to be renewed over time to try and avoid a probable memory leak. 21-Feb-2017 17:37:10.243 SEVERE [http-nio-8080-exec-6] org.apache.catalina.loader.WebappClassLoaderBase.checkThreadLocalMapForLeaks The web application [mytest] created a ThreadLocal with key of type [org.neo4j.io.pagecache.impl.muninn.CursorPool] (value [org.neo4j.io.pagecache.impl.muninn.CursorPool@33d1bad4]) and a value of type [org.neo4j.io.pagecache.impl.muninn.CursorPool.CursorSets] (value [org.neo4j.io.pagecache.impl.muninn.CursorPool$CursorSets@480122ae]) but failed to remove it when the web application was stopped. Threads are going to be renewed over time to try and avoid a probable memory leak. 21-Feb-2017 17:37:10.243 SEVERE [http-nio-8080-exec-6] org.apache.catalina.loader.WebappClassLoaderBase.checkThreadLocalMapForLeaks The web application [mytest] created a ThreadLocal with key of type [org.neo4j.io.pagecache.impl.muninn.CursorPool] (value [org.neo4j.io.pagecache.impl.muninn.CursorPool@779cb1a3]) and a value of type [org.neo4j.io.pagecache.impl.muninn.CursorPool.CursorSets] (value [org.neo4j.io.pagecache.impl.muninn.CursorPool$CursorSets@4c19623e]) but failed to remove it when the web application was stopped. Threads are going to be renewed over time to try and avoid a probable memory leak. 21-Feb-2017 17:37:10.243 SEVERE [http-nio-8080-exec-6] org.apache.catalina.loader.WebappClassLoaderBase.checkThreadLocalMapForLeaks The web application [mytest] created a ThreadLocal with key of type [org.neo4j.io.pagecache.impl.muninn.CursorPool] (value [org.neo4j.io.pagecache.impl.muninn.CursorPool@72206673]) and a value of type [org.neo4j.io.pagecache.impl.muninn.CursorPool.CursorSets] (value [org.neo4j.io.pagecache.impl.muninn.CursorPool$CursorSets@33f53ecb]) but failed to remove it when the web application was stopped. Threads are going to be renewed over time to try and avoid a probable memory leak. 21-Feb-2017 17:37:10.243 SEVERE [http-nio-8080-exec-6] org.apache.catalina.loader.WebappClassLoaderBase.checkThreadLocalMapForLeaks The web application [mytest] created a ThreadLocal with key of type [org.neo4j.io.pagecache.impl.muninn.CursorPool] (value [org.neo4j.io.pagecache.impl.muninn.CursorPool@21f680bf]) and a value of type [org.neo4j.io.pagecache.impl.muninn.CursorPool.CursorSets] (value [org.neo4j.io.pagecache.impl.muninn.CursorPool$CursorSets@26f91e2d]) but failed to remove it when the web application was stopped. Threads are going to be renewed over time to try and avoid a probable memory leak. 21-Feb-2017 17:37:10.243 SEVERE [http-nio-8080-exec-6] org.apache.catalina.loader.WebappClassLoaderBase.checkThreadLocalMapForLeaks The web application [mytest] created a ThreadLocal with key of type [org.neo4j.io.pagecache.impl.muninn.CursorPool] (value [org.neo4j.io.pagecache.impl.muninn.CursorPool@571bf77f]) and a value of type [org.neo4j.io.pagecache.impl.muninn.CursorPool.CursorSets] (value [org.neo4j.io.pagecache.impl.muninn.CursorPool$CursorSets@4d828831]) but failed to remove it when the web application was stopped. Threads are going to be renewed over time to try and avoid a probable memory leak. 21-Feb-2017 17:37:10.243 SEVERE [http-nio-8080-exec-6] org.apache.catalina.loader.WebappClassLoaderBase.checkThreadLocalMapForLeaks The web application [mytest] created a ThreadLocal with key of type [org.neo4j.io.pagecache.impl.muninn.CursorPool] (value [org.neo4j.io.pagecache.impl.muninn.CursorPool@58e40a46]) and a value of type [org.neo4j.io.pagecache.impl.muninn.CursorPool.CursorSets] (value [org.neo4j.io.pagecache.impl.muninn.CursorPool$CursorSets@36026f01]) but failed to remove it when the web application was stopped. Threads are going to be renewed over time to try and avoid a probable memory leak. 21-Feb-2017 17:37:10.243 SEVERE [http-nio-8080-exec-6] org.apache.catalina.loader.WebappClassLoaderBase.checkThreadLocalMapForLeaks The web application [mytest] created a ThreadLocal with key of type [org.neo4j.io.pagecache.impl.muninn.CursorPool] (value [org.neo4j.io.pagecache.impl.muninn.CursorPool@3eaac6b1]) and a value of type [org.neo4j.io.pagecache.impl.muninn.CursorPool.CursorSets] (value [org.neo4j.io.pagecache.impl.muninn.CursorPool$CursorSets@67300255]) but failed to remove it when the web application was stopped. Threads are going to be renewed over time to try and avoid a probable memory leak. 21-Feb-2017 17:37:10.244 SEVERE [http-nio-8080-exec-6] org.apache.catalina.loader.WebappClassLoaderBase.checkThreadLocalMapForLeaks The web application [mytest] created a ThreadLocal with key of type [org.neo4j.io.pagecache.impl.muninn.CursorPool] (value [org.neo4j.io.pagecache.impl.muninn.CursorPool@1f7e82cf]) and a value of type [org.neo4j.io.pagecache.impl.muninn.CursorPool.CursorSets] (value [org.neo4j.io.pagecache.impl.muninn.CursorPool$CursorSets@3a218c46]) but failed to remove it when the web application was stopped. Threads are going to be renewed over time to try and avoid a probable memory leak. 21-Feb-2017 17:37:10.244 SEVERE [http-nio-8080-exec-6] org.apache.catalina.loader.WebappClassLoaderBase.checkThreadLocalMapForLeaks The web application [mytest] created a ThreadLocal with key of type [org.neo4j.io.pagecache.impl.muninn.CursorPool] (value [org.neo4j.io.pagecache.impl.muninn.CursorPool@52d64afd]) and a value of type [org.neo4j.io.pagecache.impl.muninn.CursorPool.CursorSets] (value [org.neo4j.io.pagecache.impl.muninn.CursorPool$CursorSets@3513d858]) but failed to remove it when the web application was stopped. Threads are going to be renewed over time to try and avoid a probable memory leak. 21-Feb-2017 17:37:10.244 SEVERE [http-nio-8080-exec-6] org.apache.catalina.loader.WebappClassLoaderBase.checkThreadLocalMapForLeaks The web application [mytest] created a ThreadLocal with key of type [org.neo4j.io.pagecache.impl.muninn.CursorPool] (value [org.neo4j.io.pagecache.impl.muninn.CursorPool@5e104ccf]) and a value of type [org.neo4j.io.pagecache.impl.muninn.CursorPool.CursorSets] (value [org.neo4j.io.pagecache.impl.muninn.CursorPool$CursorSets@68e5b8f7]) but failed to remove it when the web application was stopped. Threads are going to be renewed over time to try and avoid a probable memory leak. 21-Feb-2017 17:37:10.244 SEVERE [http-nio-8080-exec-6] org.apache.catalina.loader.WebappClassLoaderBase.checkThreadLocalMapForLeaks The web application [mytest] created a ThreadLocal with key of type [org.neo4j.io.pagecache.impl.muninn.CursorPool] (value [org.neo4j.io.pagecache.impl.muninn.CursorPool@80486b4]) and a value of type [org.neo4j.io.pagecache.impl.muninn.CursorPool.CursorSets] (value [org.neo4j.io.pagecache.impl.muninn.CursorPool$CursorSets@237e5ef4]) but failed to remove it when the web application was stopped. Threads are going to be renewed over time to try and avoid a probable memory leak. 21-Feb-2017 17:37:10.244 SEVERE [http-nio-8080-exec-6] org.apache.catalina.loader.WebappClassLoaderBase.checkThreadLocalMapForLeaks The web application [mytest] created a ThreadLocal with key of type [org.neo4j.io.pagecache.impl.muninn.CursorPool] (value [org.neo4j.io.pagecache.impl.muninn.CursorPool@7fd41860]) and a value of type [org.neo4j.io.pagecache.impl.muninn.CursorPool.CursorSets] (value [org.neo4j.io.pagecache.impl.muninn.CursorPool$CursorSets@3a33256d]) but failed to remove it when the web application was stopped. Threads are going to be renewed over time to try and avoid a probable memory leak. 21-Feb-2017 17:37:10.244 SEVERE [http-nio-8080-exec-6] org.apache.catalina.loader.WebappClassLoaderBase.checkThreadLocalMapForLeaks The web application [mytest] created a ThreadLocal with key of type [org.neo4j.io.pagecache.impl.muninn.CursorPool] (value [org.neo4j.io.pagecache.impl.muninn.CursorPool@16ae35b9]) and a value of type [org.neo4j.io.pagecache.impl.muninn.CursorPool.CursorSets] (value [org.neo4j.io.pagecache.impl.muninn.CursorPool$CursorSets@47f65066]) but failed to remove it when the web application was stopped. Threads are going to be renewed over time to try and avoid a probable memory leak. 21-Feb-2017 17:37:10.244 SEVERE [http-nio-8080-exec-6] org.apache.catalina.loader.WebappClassLoaderBase.checkThreadLocalMapForLeaks The web application [mytest] created a ThreadLocal with key of type [org.neo4j.io.pagecache.impl.muninn.CursorPool] (value [org.neo4j.io.pagecache.impl.muninn.CursorPool@18be57e0]) and a value of type [org.neo4j.io.pagecache.impl.muninn.CursorPool.CursorSets] (value [org.neo4j.io.pagecache.impl.muninn.CursorPool$CursorSets@3b0501d7]) but failed to remove it when the web application was stopped. Threads are going to be renewed over time to try and avoid a probable memory leak. 21-Feb-2017 17:37:10.244 SEVERE [http-nio-8080-exec-6] org.apache.catalina.loader.WebappClassLoaderBase.checkThreadLocalMapForLeaks The web application [mytest] created a ThreadLocal with key of type [org.neo4j.io.pagecache.impl.muninn.CursorPool] (value [org.neo4j.io.pagecache.impl.muninn.CursorPool@5ce1e8f3]) and a value of type [org.neo4j.io.pagecache.impl.muninn.CursorPool.CursorSets] (value [org.neo4j.io.pagecache.impl.muninn.CursorPool$CursorSets@2961f669]) but failed to remove it when the web application was stopped. Threads are going to be renewed over time to try and avoid a probable memory leak. 21-Feb-2017 17:37:10.244 SEVERE [http-nio-8080-exec-6] org.apache.catalina.loader.WebappClassLoaderBase.checkThreadLocalMapForLeaks The web application [mytest] created a ThreadLocal with key of type [org.neo4j.collection.pool.MarshlandPool$1] (value [org.neo4j.collection.pool.MarshlandPool$1@438ab5f2]) and a value of type [org.neo4j.collection.pool.MarshlandPool.LocalSlot] (value [org.neo4j.collection.pool.MarshlandPool$LocalSlot@50120fed]) but failed to remove it when the web application was stopped. Threads are going to be renewed over time to try and avoid a probable memory leak. 21-Feb-2017 17:37:10.762 INFO [http-nio-8080-exec-6] org.apache.catalina.startup.HostConfig.undeploy Undeploying context [/mytest]
I've read that this warning is not necessarily an issue, but for my application this causes a real problem, because I need to access the embedded Neo4j DB via remote shell (I'm using port 5555). If I configure the embedded database to enable remote shell on port 5555, then upon shutdown the thread pool error causes the connection to port 5555 to remain active. I can only redeploy by shutting down tomcat and restarting.
I've created a simple version that only starts and stops a Neo4j embedded database, that shows the same problem (to ensure it's not a hanging DB transaction) and put the code on GitHub: https://github.com/marijnkoolen/java-jersey-neo4j-test in case someone wants to check if they can replicate this. There are no thread pool issues if I don't start an embedded database, so the problem arises in the interaction between Jersey and Neo4J. I'm not very experienced with Jersey and embedded databases, so it's very well possible I'm doing something stupid.
For ease of reading, here are relevant code snippets.
TestApplication.java:
package org.mytest; import javax.ws.rs.core.Application; import javax.annotation.PostConstruct; import javax.annotation.PreDestroy; import java.util.HashSet; import java.util.Set; import java.io.File; import org.neo4j.graphdb.GraphDatabaseService; import org.neo4j.graphdb.factory.GraphDatabaseFactory; import org.neo4j.shell.shellSettings; /** * Created by marijn on 16-2-17. */ public class TestApplication extends Application { File db_location = new File("/data/tagaid/neo4jdb"); GraphDatabaseService db; public Set> getClasses() { Set> s = new HashSet>(); s.add(HelloWorldService.class); return s; } @PostConstruct public void initialize() { try { db = new GraphDatabaseFactory().newEmbeddedDatabaseBuilder(db_location) .setConfig(shellSettings.remote_shell_enabled, "true") .setConfig(shellSettings.remote_shell_port, 5555) .newGraphDatabase(); System.out.println("Neo4j startup succeeded"); // logged in tomcat catalina.out } catch (Exception e) { e.printStackTrace(); System.out.println("Neo4j startup failed"); // logged in tomcat catalina.out } } @PreDestroy public void cleanUp() { try { db.shutdown(); System.out.println("Neo4j shutdown succeeded"); // logged in tomcat catalina.out } catch (Exception e) { e.printStackTrace(); System.out.println("Neo4j shutdown failed!"); // logged in tomcat catalina.out } db = null; // should not be necessary } }
web.xml:
<!DOCTYPE web-app PUBLIC
"-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd" >
<web-app>
<display-name>Archetype Created Web Application</display-name>
<servlet>
<servlet-name>jersey-servlet</servlet-name>
<servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>jersey.config.server.provider.packages</param-name>
<param-value>com.marijn.jerseytest</param-value>
</init-param>
<init-param>
<param-name>javax.ws.rs.Application</param-name>
<param-value>org.mytest.TestApplication</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>jersey-servlet</servlet-name>
<url-pattern>/rest/*</url-pattern>
</servlet-mapping>
</web-app>
pom.xml:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.mytest</groupId>
<artifactId>org.mytest</artifactId>
<packaging>war</packaging>
<version>1.0-SNAPSHOT</version>
<name>org.mytest Maven Webapp</name>
<url>http://maven.apache.org</url>
<dependencies>
<dependency>
<groupId>se.jiderhamn</groupId>
<artifactId>classloader-leak-prevention</artifactId>
<scope>runtime</scope>
<version>1.15.4</version>
<exclusions>
<exclusion>
<artifactId>servlet-api</artifactId>
<groupId>javax.servlet</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.core</groupId>
<artifactId>jersey-server</artifactId>
<version>2.22.1</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.containers</groupId>
<artifactId>jersey-container-servlet-core</artifactId>
<version>2.22.1</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.test-framework.providers</groupId>
<artifactId>jersey-test-framework-provider-jdk-http</artifactId>
<version>2.22.1</version>
</dependency>
<dependency>
<groupId>javax.ws.rs</groupId>
<artifactId>javax.ws.rs-api</artifactId>
<version>2.0</version>
</dependency>
<dependency>
<groupId>org.neo4j</groupId>
<artifactId>neo4j</artifactId>
<version>3.1.1</version>
</dependency>
<dependency>
<groupId>org.neo4j</groupId>
<artifactId>neo4j-io</artifactId>
<version>3.1.1</version>
</dependency>
<dependency>
<groupId>org.neo4j</groupId>
<artifactId>neo4j-kernel</artifactId>
<version>3.1.1</version>
</dependency>
<dependency>
<groupId>org.neo4j</groupId>
<artifactId>neo4j-shell</artifactId>
<version>3.1.1</version>
</dependency>
</dependencies>
<build>
<finalName>org.mytest</finalName>
<plugins>
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.2</version>
<configuration>
<url>http://localhost:8080/manager/text</url>
<server>UnixTomcatServer</server>
<path>/mytest</path>
</configuration>
</plugin>
</plugins>
</build>
</project>
In the catalina.out log I can see that the @PostConstruct and @PreDestroy functions are called and the shutdown is executed. Then the thread pool warning is logged. I've tried the JVMHelper that was suggested for a similar issue (https://github.com/Neo4j/Neo4j/issues/1070) which kills many threads and takes care of the ThreadLocal errors, but not the thread pool issue.
Setup:
- Java version: 1.8.0_121
- Maven version: 3.3.9
Tested in the original application with:
- tomcat versions 6, 8 and 9
- Neo4j versions 2.2.3, 2.2.5 and 3.1
- Jersey versions 1.19 and 2.22.1
In the simple app reported here:
- Tomcat 8 and 9
- Neo4j 3.1
- Jersey 2.22.1
Any help would be appreciated.
Many thanks,
Marijn
Update 2017-03-02 I've updated to Tomcat 9 and added the remote shell connection to the application code above. In the GitHub repo I made I've added a simple unit test as suggested by @jerome-b to show that the remote shell port is not released upon shutdown.