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

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

Neo4j:遍历查询超时

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

在過去的幾周中,我一直在花一些業余時間來創建一個應用程序,該應用程序從Open Roads數據生成運行路線-當然已轉換并導入到Neo4j中!

我創建了一個用戶定義的過程,該過程結合了幾個最短路徑查詢,但是如果它們花費的時間太長,我想退出所有這些最短路徑搜索。 我的代碼沒有超時看起來像這樣:

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

我們可以在幾個地方檢查經過的時間,但是對我來說, 擴展器中的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();} }

現在需要更新較早版本的代碼片段,以使用我們的新類,這不太麻煩:

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 ); ...

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

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

總結

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

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。