[英]What is the maximum Duration in Java Akka API?
I'm working with the Akka Java library (unfortunately, the Classic version).我正在使用 Akka Java 库(不幸的是,经典版本)。 When implementing the fault tolerance Strategy, the documentation provide a snippet like this:在实施容错策略时, 文档提供了这样的片段:
private static SupervisorStrategy strategy =
new OneForOneStrategy(
10,
Duration.ofMinutes(1), // <----- Note here!
DeciderBuilder.match(...)
.build();
Moreover, it says: "Also, there are special values for these parameters. If you specify: -1
to maxNrOfRetries
, and Duration.Inf()
to withinTimeRange
, then the child is always restarted without any limit".此外,它说:“此外,这些参数有特殊值。如果您指定: -1
到maxNrOfRetries
,以及Duration.Inf()
到withinTimeRange
,那么孩子总是重新启动,没有任何限制”。 The problem is that, in my Java (openjdk-11), Duration.Inf()
doesn't actually exist!问题是,在我的 Java (openjdk-11) 中, Duration.Inf()
实际上并不存在! . .
I have read some SO answers that specify what is the effective maximum Duration, but Akka seem to not recognize them.我已经阅读了一些 SO 答案,这些答案指定了有效的最大持续时间,但 Akka 似乎无法识别它们。 The best I could do is to specify Duration.ofNanos(Long.MAX_VALUE)
.我能做的最好的就是指定Duration.ofNanos(Long.MAX_VALUE)
。
Am I missing something?我错过了什么吗? Is there actually a value to input or is the Akka documentation just wrong?实际上是否有输入值或者 Akka 文档是错误的?
The Duration.Inf()
there isn't referring to java.time.Duration
(even though the snippet above that in the docs does use the Java Duration
API). Duration.Inf()
没有引用java.time.Duration
(即使文档中上面的代码片段确实使用了 Java Duration
API)。 Under the hood, Akka converts the Java Duration
to a scala.concurrent.duration.Duration
, which does have an Inf
(the naming pattern indicates that it's a constant in Scala) which is defined to be greater than any FiniteDuration
).在底层,Akka 将 Java Duration
转换为scala.concurrent.duration.Duration
,它确实有一个Inf
(命名模式表明它是 Scala 中的一个常量),它被定义为大于任何FiniteDuration
)。 The Java API just has a constructor which takes java.time.Duration
. Java API 只有一个构造函数,它采用java.time.Duration
。
This should work:这应该有效:
new OneForOneStrategy(
10,
scala.concurrent.duration.Duration.Inf(),
true, // have to explicitly pass the default loggingEnabled
DeciderBuilder.match(...).build()
);
The maximum value of a Java Duration
is Duration.ofSeconds(Long.MAX_VALUE).plusNanos(999999999)
. Java Duration
的最大值是Duration.ofSeconds(Long.MAX_VALUE).plusNanos(999999999)
。 Note that inside Akka, when converted to Scala Duration
this will be considered less than an infinite duration, but that probably doesn't matter.请注意,在 Akka 内部,当转换为 Scala Duration
时,这将被视为小于无限持续时间,但这可能并不重要。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.