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

歡迎訪問(wèn) 生活随笔!

生活随笔

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

编程问答

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

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

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)題。

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