neo4j 连接超时_Neo4j:遍历查询超时
neo4j 連接超時(shí)
在過(guò)去的幾周中,我一直在花一些業(yè)余時(shí)間來(lái)創(chuàng)建一個(gè)應(yīng)用程序,該應(yīng)用程序從Open Roads數(shù)據(jù)生成運(yùn)行路線-當(dāng)然,已轉(zhuǎn)換并導(dǎo)入了Neo4j!
我創(chuàng)建了一個(gè)用戶定義的過(guò)程,該過(guò)程結(jié)合了幾個(gè)最短路徑查詢,但是如果它們花費(fèi)的時(shí)間太長(zhǎng),我想退出所有這些最短路徑搜索。 我的代碼沒(méi)有超時(shí)如下所示:
StandardExpander orderedExpander = new OrderedByTypeExpander().add( RelationshipType.withName( "CONNECTS" ), Direction.BOTH );PathFinder<Path> shortestPathFinder = GraphAlgoFactory.shortestPath( expander, 250 );...在很多地方,我們都可以檢查經(jīng)過(guò)的時(shí)間,但是對(duì)我來(lái)說(shuō), 擴(kuò)展器中的expand方法似乎很明顯。 我編寫了自己的Expander類,如下所示:
public class TimeConstrainedExpander implements PathExpander {private final StandardExpander expander;private final long startTime;private final Clock clock;private int pathsExpanded = 0;private long timeLimitInMillis;public TimeConstrainedExpander( StandardExpander expander, Clock clock, long timeLimitInMillis ){this.expander = expander;this.clock = clock;this.startTime = clock.instant().toEpochMilli();this.timeLimitInMillis = timeLimitInMillis;}@Overridepublic Iterable<Relationship> expand( Path path, BranchState state ){long timeSoFar = clock.instant().toEpochMilli() - startTime;if ( timeSoFar > timeLimitInMillis ){return Collections.emptyList();}return expander.expand( path, state );}@Overridepublic PathExpander reverse(){return expander.reverse();} }現(xiàn)在需要更新較早版本的代碼片段以使用我們的新類,這不太麻煩:
StandardExpander orderedExpander = new OrderedByTypeExpander().add( RelationshipType.withName( "CONNECTS" ), Direction.BOTH );TimeConstrainedExpander expander = new TimeConstrainedExpander(orderedExpander, Clock.systemUTC(), 200);PathFinder<Path> shortestPathFinder = GraphAlgoFactory.shortestPath( expander, 250 ); ...我不確定這是否是實(shí)現(xiàn)我想要的最佳方法,但是在其他幾種方法失敗之后,至少這種方法確實(shí)有效!
翻譯自: https://www.javacodegeeks.com/2017/11/neo4j-traversal-query-timeout.html
neo4j 連接超時(shí)
總結(jié)
以上是生活随笔為你收集整理的neo4j 连接超时_Neo4j:遍历查询超时的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: 极摩客推出 NucBox M3 迷你 P
- 下一篇: openhub_介绍OpenHub框架