嵌入式Neo4J的Jersey Web应用程序无法在Tomcat服务器

时间:2017-02-22 16:42:34

标签: java tomcat neo4j jersey

初步:我在SO上寻找类似的问题,与我最相似的是:Unable to shut down neo4j jetty server within tomcat。我已经尝试了那里提出的所有解决方案但没有成功。

在Tomcat上运行带有嵌入式Neo4j数据库的Jersey应用程序时,我遇到了关机问题。部署(使用Maven 3.3.9)工作正常并且数据库已启动,但在重新部署/取消部署时,我收到Tomcat警告:


    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]

我已经读过这个警告不一定是个问题,但是对于我的应用程序来说这会引起一个真正的问题,因为我需要通过远程shell访问嵌入式Neo4j DB(我使用的是端口5555)。如果我将嵌入式数据库配置为在端口5555上启用远程shell,则在关闭时,线程池错误会导致与端口5555的连接保持活动状态。我只能通过关闭tomcat并重新启动来重新部署。

我创建了一个只启动和停止Neo4j嵌入式数据库的简单版本,它显示了同样的问题(以确保它不是挂起的数据库事务)并将代码放在GitHub上:https://github.com/marijnkoolen/java-jersey-neo4j-test以防万一想检查一下他们是否可以复制这个。如果我不启动嵌入式数据库,则没有线程池问题,因此Jersey和Neo4J之间的交互出现了问题。我对Jersey和嵌入式数据库不是很有经验,所以我很可能做一些愚蠢的事情。

为便于阅读,以下是相关的代码段。

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>

在catalina.out日志中,我可以看到调用@PostConstruct和@PreDestroy函数并执行关闭。然后记录线程池警告。我已经尝试过针对类似问题(https://github.com/Neo4j/Neo4j/issues/1070)建议的JVMHelper,它会杀死许多线程并处理ThreadLocal错误,但不会解决线程池问题。

设定:

  • Java版本:1.8.0_121
  • Maven版本:3.3.9

在原始应用程序中测试:

  • tomcat版本6,8和9
  • Neo4j版本2.2.3,2.2.5和3.1
  • Jersey版本1.19和2.22.1

在这里报道的简单应用中:

  • Tomcat 8 and 9
  • Neo4j 3.1
  • Jersey 2.22.1

任何帮助将不胜感激。

非常感谢,

Marijn

更新2017-03-02 我已更新到Tomcat 9并将远程shell连接添加到上面的应用程序代码中。在我做的GitHub回购中,我添加了一个简单的单元测试,如@jerome-b所示,表明远程shell端口在关闭时没有释放。

1 个答案:

答案 0 :(得分:0)

我向Neo4J提出了一个问题(#8929)。这是一个错误(端口在JVM终止之前一直保持绑定状态),并在问题#8949中提出修复。