AKKA 在一段时间后停止记录堆栈跟踪

AKKA stops logging stack traces after a while

我在使用 Akka 和 Play 2.3 (Java) 时遇到了一个非常奇怪的问题。

我有一堆具有非常标准的 slf4J 日志记录的演员:

public abstract class ScheduledJob extends UntypedActor {
    protected final LoggingAdapter logger = Logging.getLogger(getContext().system(), this);

我的 akka.conf 看起来像这样

akka {
         loggers = ["akka.event.slf4j.Slf4jLogger"]
         loglevel = "DEBUG"
                actor {
                  default-dispatcher = {
                     fork-join-executor {
                     parallelism-factor = 4.0
                     parallelism-max = 200
                   }
                 }
               }
          }

我的错误有一段时间是这样的:

[2015-06-02 11:25:37,772] - [ERROR] - from akka.actor.OneForOneStrategy at [akka://application/user/distributor-anchor/router]
null
java.lang.NullPointerException: null
        at services.analytics.thirdparty.ServiceImpl.track(ServiceImpl.java:175) ~[tf-rest-play.tf-rest-play-1.0-SNAPSHOT.jar:1.0-SNAPSHOT]
        at actor.services.analytics.DistributorActor.lambda$track(DistributorActor.java:146) ~[tf-rest-play.tf-rest-play-1.0-SNAPSHOT.jar:1.0-SNAPSHOT]
        at actor.services.analytics.DistributorActor$$Lambda/1308315289.accept(Unknown Source) ~[na:na]
        at java.util.Iterator.forEachRemaining(Iterator.java:116) ~[na:1.8.0_40]
        at java.util.Spliterators$IteratorSpliterator.forEachRemaining(Spliterators.java:1801) ~[na:1.8.0_40]
        at java.util.stream.ReferencePipeline$Head.forEach(ReferencePipeline.java:580) ~[na:1.8.0_40]
        at actor.services.analytics.DistributorActor.track(DistributorActor.java:145) ~[tf-rest-play.tf-rest-play-1.0-SNAPSHOT.jar:1.0-SNAPSHOT]
        at actor.services.analytics.DistributorActor.onReceive(DistributorActor.java:54) ~[tf-rest-play.tf-rest-play-1.0-SNAPSHOT.jar:1.0-SNAPSHOT]
        at akka.actor.UntypedActor$$anonfun$receive.applyOrElse(UntypedActor.scala:167) ~[com.typesafe.akka.akka-actor_2.10-2.3.4.jar:na]
        at akka.actor.Actor$class.aroundReceive(Actor.scala:465) ~[com.typesafe.akka.akka-actor_2.10-2.3.4.jar:na]
        at akka.actor.UntypedActor.aroundReceive(UntypedActor.scala:97) ~[com.typesafe.akka.akka-actor_2.10-2.3.4.jar:na]
        at akka.actor.ActorCell.receiveMessage(ActorCell.scala:516) [com.typesafe.akka.akka-actor_2.10-2.3.4.jar:na]
        at akka.actor.ActorCell.invoke(ActorCell.scala:487) [com.typesafe.akka.akka-actor_2.10-2.3.4.jar:na]
        at akka.dispatch.Mailbox.processMailbox(Mailbox.scala:238) [com.typesafe.akka.akka-actor_2.10-2.3.4.jar:na]
        at akka.dispatch.Mailbox.run(Mailbox.scala:220) [com.typesafe.akka.akka-actor_2.10-2.3.4.jar:na]
        at akka.dispatch.ForkJoinExecutorConfigurator$AkkaForkJoinTask.exec(AbstractDispatcher.scala:393) [com.typesafe.akka.akka-actor_2.10-2.3.4.jar:na]
        at scala.concurrent.forkjoin.ForkJoinTask.doExec(ForkJoinTask.java:260) [org.scala-lang.scala-library-2.10.4.jar:na]
        at scala.concurrent.forkjoin.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1339) [org.scala-lang.scala-library-2.10.4.jar:na]
        at scala.concurrent.forkjoin.ForkJoinPool.runWorker(ForkJoinPool.java:1979) [org.scala-lang.scala-library-2.10.4.jar:na]
        at scala.concurrent.forkjoin.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:107) [org.scala-lang.scala-library-2.10.4.jar:na]

经过一段不确定的(8-24 小时)时间后,堆栈跟踪消失,同样的错误输出如下:

[2015-06-02 17:33:43,338] - [ERROR] - from akka.actor.OneForOneStrategy at [akka://application/user/distributor-anchor/router]
 null
 java.lang.NullPointerException: null

我 100% 确定以上两个错误是相同的(即它们由相同的条件引起并在代码中的相同位置抛出)但无法确定堆栈跟踪从中消失的原因一段时间后的日志输出。重新启动可以解决问题(直到它最终恢复)。

这是 JVM 的正常行为,您可以使用 -XX:-OmitStackTraceInFastThrow.

关闭预分配异常的使用