Java Akka API的最大持续时间是多少?

发布于 2025-02-12 02:05:04 字数 885 浏览 1 评论 0 原文

我正在使用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文档只是错误的?

I'm working with the Akka Java library (unfortunately, the Classic version). 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".
The problem is that, in my Java (openjdk-11), Duration.Inf() doesn't actually exist!.

I have read some SO answers that specify what is the effective maximum Duration, but Akka seem to not recognize them. The best I could do is to specify Duration.ofNanos(Long.MAX_VALUE).

Am I missing something? Is there actually a value to input or is the Akka documentation just wrong?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

残龙傲雪 2025-02-19 02:05:04

duration.inf()没有参考 java.time.duration (即使文档中上方的摘要确实使用Java 持续时间< /代码> API)。在引擎盖下,akka将java 持续时间转换为 scala.concurrent.duration.duration.duration.duration ,它确实具有 inf> inf (命名模式指示指示它是Scala中的常数),定义为大于任何 finiteduration )。 Java API只有一个构造函数,该构造函数采用 java.time.duration

这应该有效:

new OneForOneStrategy(
    10,
    scala.concurrent.duration.Duration.Inf(),
    true,  // have to explicitly pass the default loggingEnabled
    DeciderBuilder.match(...).build()
);

java 持续时间的最大值是持续时间。请注意,在Akka内部,当转换为Scala 持续时间时,这将被视为小于无限持续时间,但这可能可能并不重要。

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). 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). The Java API just has a constructor which takes 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). Note that inside Akka, when converted to Scala Duration this will be considered less than an infinite duration, but that probably doesn't matter.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文