有了自己的域名怎么做网站,电商网站建设目的及网站的优势,网页设计与自学教程,手机百度app下载安装在过去的几周中#xff0c;我一直在花一些业余时间来创建一个应用程序#xff0c;该应用程序从Open Roads数据生成运行路线-当然已转换并导入到Neo4j中#xff01; 我创建了一个用户定义的过程#xff0c;该过程结合了几个最短路径查询#xff0c;但是如果它们花费的时间… 在过去的几周中我一直在花一些业余时间来创建一个应用程序该应用程序从Open Roads数据生成运行路线-当然已转换并导入到Neo4j中 我创建了一个用户定义的过程该过程结合了几个最短路径查询但是如果它们花费的时间太长我想退出所有这些最短路径搜索。 我的代码没有超时看起来像这样 StandardExpander orderedExpander new OrderedByTypeExpander().add( RelationshipType.withName( CONNECTS ), Direction.BOTH );PathFinderPath 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 IterableRelationship 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);PathFinderPath shortestPathFinder GraphAlgoFactory.shortestPath( expander, 250 );
... 我不确定这是否是实现我想要的最佳方法但是在其他几种方法失败之后至少这种方法确实有效 翻译自: https://www.javacodegeeks.com/2017/11/neo4j-traversal-query-timeout.html