日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

neo4j 连接超时_Neo4j:遍历查询超时

發(fā)布時間:2023/12/3 编程问答 27 豆豆
生活随笔 收集整理的這篇文章主要介紹了 neo4j 连接超时_Neo4j:遍历查询超时 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

neo4j 連接超時

在過去的幾周中,我一直在花一些業(yè)余時間來創(chuàng)建一個應(yīng)用程序,該應(yīng)用程序從Open Roads數(shù)據(jù)生成運行路線-當(dāng)然,已轉(zhuǎn)換并導(dǎo)入了Neo4j!

我創(chuàng)建了一個用戶定義的過程,該過程結(jié)合了幾個最短路徑查詢,但是如果它們花費的時間太長,我想退出所有這些最短路徑搜索。 我的代碼沒有超時如下所示:

StandardExpander orderedExpander = new OrderedByTypeExpander().add( RelationshipType.withName( "CONNECTS" ), Direction.BOTH );PathFinder<Path> shortestPathFinder = GraphAlgoFactory.shortestPath( expander, 250 );...

在很多地方,我們都可以檢查經(jīng)過的時間,但是對我來說, 擴展器中的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 ); ...

我不確定這是否是實現(xiàn)我想要的最佳方法,但是在其他幾種方法失敗之后,至少這種方法確實有效!

翻譯自: https://www.javacodegeeks.com/2017/11/neo4j-traversal-query-timeout.html

neo4j 連接超時

總結(jié)

以上是生活随笔為你收集整理的neo4j 连接超时_Neo4j:遍历查询超时的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。