创建相同Neo4j数据库的两个实例

时间:2014-04-24 10:48:27

标签: multithreading neo4j

我有两个线程,第一个使用爬虫收集数据并创建Neo4j图数据库,第二个执行每十分钟一些查询,例如到目前为止添加了多少个节点以分析图。我的问题是,当第一个线程运行时,我无法运行第二个线程,因为我无法创建数据库的新实例。它返回以下错误:

    Exception in thread "Thread-6" java.lang.RuntimeException: org.neo4j.kernel.lifecycle.LifecycleException: Component 'org.neo4j.kernel.StoreLockerLifecycleAdapter@b7c0a73' was successfully initialized, but failed to start. Please see attached cause exception.
    at com.tinkerpop.blueprints.impls.neo4j.Neo4jGraph.<init>(Neo4jGraph.java:165)
    at com.tinkerpop.blueprints.impls.neo4j.Neo4jGraph.<init>(Neo4jGraph.java:135)
    at main.AnalyzeGraph.run(AnalyzeGraph.java:28)
    at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.RuntimeException: org.neo4j.kernel.lifecycle.LifecycleException: Component 'org.neo4j.kernel.StoreLockerLifecycleAdapter@b7c0a73' was successfully initialized, but failed to start. Please see attached cause exception.
    at org.neo4j.kernel.InternalAbstractGraphDatabase.run(InternalAbstractGraphDatabase.java:281)
    at org.neo4j.kernel.EmbeddedGraphDatabase.<init>(EmbeddedGraphDatabase.java:106)
    at org.neo4j.kernel.EmbeddedGraphDatabase.<init>(EmbeddedGraphDatabase.java:81)
    at org.neo4j.kernel.EmbeddedGraphDatabase.<init>(EmbeddedGraphDatabase.java:63)
    at com.tinkerpop.blueprints.impls.neo4j.Neo4jGraph.<init>(Neo4jGraph.java:155)
    ... 3 more
Caused by: org.neo4j.kernel.lifecycle.LifecycleException: Component 'org.neo4j.kernel.StoreLockerLifecycleAdapter@b7c0a73' was successfully initialized, but failed to start. Please see attached cause exception.
    at org.neo4j.kernel.lifecycle.LifeSupport$LifecycleInstance.start(LifeSupport.java:497)
    at org.neo4j.kernel.lifecycle.LifeSupport.start(LifeSupport.java:104)
    at org.neo4j.kernel.InternalAbstractGraphDatabase.run(InternalAbstractGraphDatabase.java:259)
    ... 7 more
Caused by: org.neo4j.kernel.StoreLockException: Unable to obtain lock on store lock file: /home/sotbeis/Desktop/neo4jDB/store_lock. Please ensure no other process is using this database, and that the directory is writable (required even for read-only access)
    at org.neo4j.kernel.StoreLocker.checkLock(StoreLocker.java:79)
    at org.neo4j.kernel.StoreLockerLifecycleAdapter.start(StoreLockerLifecycleAdapter.java:40)
    at org.neo4j.kernel.lifecycle.LifeSupport$LifecycleInstance.start(LifeSupport.java:491)
    ... 9 more
Caused by: java.nio.channels.OverlappingFileLockException
    at sun.nio.ch.SharedFileLockTable.checkList(FileLockTable.java:255)
    at sun.nio.ch.SharedFileLockTable.add(FileLockTable.java:152)
    at sun.nio.ch.FileChannelImpl.tryLock(FileChannelImpl.java:1056)
    at java.nio.channels.FileChannel.tryLock(FileChannel.java:1154)
    at org.neo4j.kernel.impl.nioneo.store.FileLock.getOsSpecificFileLock(FileLock.java:83)
    at org.neo4j.kernel.DefaultFileSystemAbstraction.tryLock(DefaultFileSystemAbstraction.java:83)
    at org.neo4j.kernel.StoreLocker.checkLock(StoreLocker.java:70)
    ... 11 more

有没有办法解决这个问题?请注意,我无法将第一个neo4j图形数据库实例传递给第二个线程。

我使用blueprints-neo4j-graph 2.4.0。

编辑:我使用的是嵌入式版本

2 个答案:

答案 0 :(得分:0)

假设您使用的是嵌入式版本,我认为不可能拥有相同图表数据库的多个实例。

点击此处,虽然我不认为如果您无法将图表数据库实例传入线程,这对您有所帮助:https://groups.google.com/forum/#!topic/nosql-databases/z9nZ80ow5QY

...但是,如果可以,那么解决方案变得相当直接,例如单身等等。

此外,文档中的这一点暗示您只能在多个线程之间共享实例:http://docs.neo4j.org/chunked/stable/tutorials-java-embedded-hello-world.html

因此,根据我的经验和我一直在阅读的内容,您不能在应用程序中运行多个Neo4j实例;无论如何,这在很大程度上是有意义的,考虑到锁定问题和什么不是。

答案 1 :(得分:0)

如果您无法在线程之间共享图形实例,则可能意味着您有一个更适合Neo4J服务器的用例。

相关问题