创建maven项目以在neo4j服务器上运行时出错

时间:2015-04-18 05:49:08

标签: neo4j

如何解决此异常:

  

线程中的异常" main"   org.neo4j.kernel.lifecycle.LifecycleException:无法转换   零件   ' org.neo4j.kernel.impl.pagecache.PageCacheLifecycle@4b845428'从   停止了SHUTTING_DOWN。请参阅附件原因例外   org.neo4j.kernel.lifecycle.LifeSupport $ LifecycleInstance.shutdown(LifeSupport.java:559)     在   org.neo4j.kernel.lifecycle.LifeSupport.shutdown(LifeSupport.java:200)     在   org.neo4j.kernel.InternalAbstractGraphDatabase.shutdown(InternalAbstractGraphDatabase.java:685)     在   org.neo4j.kernel.InternalAbstractGraphDatabase.run(InternalAbstractGraphDatabase.java:340)     在   org.neo4j.kernel.EmbeddedGraphDatabase。(EmbeddedGraphDatabase.java:59)     在   org.neo4j.graphdb.factory.GraphDatabaseFactory.newDatabase(GraphDatabaseFactory.java:108)     在   org.neo4j.graphdb.factory.GraphDatabaseFactory $ 1.newDatabase(GraphDatabaseFactory.java:95)     在   org.neo4j.graphdb.factory.GraphDatabaseBuilder.newGraphDatabase(GraphDatabaseBuilder.java:176)     在   org.neo4j.graphdb.factory.GraphDatabaseFactory.newEmbeddedDatabase(GraphDatabaseFactory.java:67)     在neo4jExamples.secondExample.main(secondExample.java:18)引起:   java.lang.IllegalStateException:无法关闭PageCache   文件仍然映射:neostore.relationshiptypestore.db.names(1   映射)   org.neo4j.io.pagecache.impl.muninn.MuninnPageCache.close(MuninnPageCache.java:473)     在   org.neo4j.kernel.impl.pagecache.PageCacheLifecycle.shutdown(PageCacheLifecycle.java:42)     在   org.neo4j.kernel.lifecycle.LifeSupport $ LifecycleInstance.shutdown(LifeSupport.java:555)     ... 9更多

我的代码是:

package neo4jExamples;
import org.neo4j.graphdb.GraphDatabaseService;
import org.neo4j.graphdb.Node;
import org.neo4j.graphdb.Relationship;
import org.neo4j.graphdb.Transaction;
import org.neo4j.graphdb.factory.GraphDatabaseFactory;

public class secondExample {

    public static void main(String[] args) {

        GraphDatabaseService graphDb;
        Node firstNode;
        Node secondNode;
        Relationship relationship;

        graphDb = new GraphDatabaseFactory().newEmbeddedDatabase("/var/lib/neo4j/data/graph.db");
        registerShutdownHook( graphDb );

        try (Transaction tx = graphDb.beginTx()) {

            firstNode = graphDb.createNode();
            firstNode.setProperty( "message", "Hello, " );
            secondNode = graphDb.createNode();
            secondNode.setProperty( "message", "World!" );

            relationship = firstNode.createRelationshipTo( secondNode, RelTypes.KNOWS );
            relationship.setProperty( "message", "brave Neo4j " );

            System.out.print( firstNode.getProperty( "message" ) );
            System.out.print( relationship.getProperty( "message" ) );
            System.out.print( secondNode.getProperty( "message" ) );


            tx.success();
        }

    }

    private static void registerShutdownHook(final GraphDatabaseService graphDb) {

            Runtime.getRuntime().addShutdownHook(new Thread() {
                @Override
                public void run() {
                    graphDb.shutdown();
                }
            });
        }

    }

1 个答案:

答案 0 :(得分:2)

我可以在这里想到两个原因:

  1. 另一个java进程正在访问某些文件,除非其他内容有助于考虑kill -9 <pid>
  2. 仔细检查graph.db文件夹中的文件权限。