Java Akka API的最大持续时间是多少?
我正在使用Akka Java库(不幸的是,经典版本)。实施容忍策略时,提供类似的片段:
private static SupervisorStrategy strategy =
new OneForOneStrategy(
10,
Duration.ofMinutes(1), // <----- Note here!
DeciderBuilder.match(...)
.build();
此外,它说:
“此外,这些参数也有特殊的值。如果指定:
-1
to maxnrofretries
和 lisation.inf()
to withintimerange ,那么孩子总是在没有任何任何的情况下重新启动。限制”。
问题在于,在我的Java(OpenJDK-11)中, duration.inf()
实际上并不存在!。
我已经阅读了一些答案,可以说明什么是有效的最大持续时间,但是Akka似乎不认识它们。我能做的最好的方法是指定 duration.ofnanos(long.max_value)
。
我想念什么吗?实际上有一个值的价值,还是Akka文档只是错误的?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
duration.inf()
没有参考java.time.duration
(即使文档中上方的摘要确实使用Java持续时间< /代码> API)。在引擎盖下,akka将java
持续时间
转换为scala.concurrent.duration.duration.duration.duration
,它确实具有inf> inf
(命名模式指示指示它是Scala中的常数),定义为大于任何finiteduration
)。 Java API只有一个构造函数,该构造函数采用java.time.duration
。这应该有效:
java
持续时间
的最大值是持续时间。请注意,在Akka内部,当转换为Scala
持续时间
时,这将被视为小于无限持续时间,但这可能可能并不重要。The
Duration.Inf()
there isn't referring tojava.time.Duration
(even though the snippet above that in the docs does use the JavaDuration
API). Under the hood, Akka converts the JavaDuration
to ascala.concurrent.duration.Duration
, which does have anInf
(the naming pattern indicates that it's a constant in Scala) which is defined to be greater than anyFiniteDuration
). The Java API just has a constructor which takesjava.time.Duration
.This should work:
The maximum value of a Java
Duration
isDuration.ofSeconds(Long.MAX_VALUE).plusNanos(999999999)
. Note that inside Akka, when converted to ScalaDuration
this will be considered less than an infinite duration, but that probably doesn't matter.