[英]java process won't stop after neo4j query
I'm connecting to a remote neo4j db using ConfigrationSource
and SessionFactory
from neo4j OGM like this:我正在使用来自neo4j OGM的
ConfigrationSource
和SessionFactory
连接到远程neo4j数据库,如下所示:
private final static ConfigurationSource props = new ClasspathConfigurationSource("neo4j-connection.properties");
private final static Configuration configuration = new Configuration.Builder(props).build();
private final static SessionFactory sessionFactory = new SessionFactory(configuration, "domain");
Then I run a cypher query and get back an Iterable of POJO mapped to neo4j nodes with OGM annotations然后我运行一个密码查询并取回一个 Iterable 的 POJO 映射到带有 OGM 注释的 neo4j 节点
private final LinkedBlockingQueue<Session> sessionPool = new LinkedBlockingQueue<>(8192);
@Override
public Iterable<Location> findAll() {
try {
return session.loadAll(Location.class, 1);
} finally {
closeSession(session);
}
}
private void closeSession(Session session) {
if (session != null) {
try {
sessionPool.offer(session, 100, TimeUnit.MILLISECONDS);
} catch (Throwable e) {
e.printStackTrace();
}
}
}
Everything works fine, in my main method I have my POJO object created with neo4j values一切正常,在我的主要方法中,我使用 neo4j 值创建了 POJO 对象
public static void main(String[] args) {
LocationServiceImpl locationService = new LocationServiceImpl();
Iterable<Location> locations = locationService.findAll();
for(Location location : locations) {
System.out.println(location.getSubType());//eg. prints Floor, Building etc
}
System.out.println("End");
}
But after the main method finishes the app won't stop.但是在 main 方法完成后,应用程序不会停止。 Above "End" string being printed.
正在打印的“End”字符串上方。 So some thread is hanging somewhere and I can't figure out where and why.
所以有些线程挂在某处,我不知道在哪里以及为什么。
I tried closing the neo4j ogm session but with no luck.我尝试关闭 neo4j ogm 会话,但没有成功。
My neo4j ogm pom dependencies我的 neo4j ogm pom 依赖项
<dependency>
<groupId>org.neo4j</groupId>
<artifactId>neo4j-ogm-bolt-driver</artifactId>
<version>3.1.2</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.neo4j</groupId>
<artifactId>neo4j-jdbc-driver</artifactId>
<version>3.4.0</version>
</dependency>
<dependency>
<groupId>org.neo4j</groupId>
<artifactId>neo4j-ogm-core</artifactId>
<version>3.1.3</version>
</dependency>
You have to close the SessionFactory
as well.您还必须关闭
SessionFactory
。
Some background: I assume that you are using the Bolt protocol for the connection.一些背景:我假设您使用 Bolt 协议进行连接。 Creating an instance of
SessionFactory
will also create a java (bolt) driver instance with all its connection pooling etc. To have a clean shutdown call sessionFactory.close()
that will also shutdown / close the driver.创建
SessionFactory
的实例还将创建一个 java (bolt) 驱动程序实例及其所有连接池等。要进行干净的关闭调用sessionFactory.close()
也将关闭/关闭驱动程序。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.