gpt4 book ai didi

java - 在另一个库中配置ActorSystem

转载 作者:行者123 更新时间:2023-11-30 05:35:28 26 4
gpt4 key购买 nike

我的应用程序使用一个库,该库在内部初始化一个参与者系统,如下所示

ActorSystem("MySys")

因此,MySys actor 系统使用默认调度程序。我想为这个特定的参与者系统使用自定义调度程序。如何在我的 application.conf 中覆盖该库的 actor 系统使用的调度程序?

我已经尝试过这样做

MySys {
akka {
actor {
default-dispatcher = "my-dispatcher"
}

my-dispatcher {
type = Dispatcher
executor = "thread-pool-executor"
thread-pool-executor {
fixed-pool-size = 85
}
}

}
}

但是这不起作用,因为线程转储显示以下输出

"MySys-akka.actor.default-dispatcher-6" #396 prio=5 os_prio=0 tid=0x00007f54501b6000 nid=0x1a6 waiting on condition [0x00007f55285f3000]
java.lang.Thread.State: WAITING (parking)
at sun.misc.Unsafe.park(Native Method)
- parking to wait for <0x00000000e4b5b1f0> (a akka.dispatch.ForkJoinExecutorConfigurator$AkkaForkJoinPool)
at akka.dispatch.forkjoin.ForkJoinPool.scan(ForkJoinPool.java:2075)
at akka.dispatch.forkjoin.ForkJoinPool.runWorker(ForkJoinPool.java:1979)
at akka.dispatch.forkjoin.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:107)

"MySys-akka.actor.default-dispatcher-5" #363 prio=5 os_prio=0 tid=0x00007f545c006800 nid=0x185 waiting on condition [0x00007f5443acf000]
java.lang.Thread.State: TIMED_WAITING (parking)
at sun.misc.Unsafe.park(Native Method)
- parking to wait for <0x00000000e4b5b1f0> (a akka.dispatch.ForkJoinExecutorConfigurator$AkkaForkJoinPool)
at akka.dispatch.forkjoin.ForkJoinPool.idleAwaitWork(ForkJoinPool.java:2135)
at akka.dispatch.forkjoin.ForkJoinPool.scan(ForkJoinPool.java:2067)
at akka.dispatch.forkjoin.ForkJoinPool.runWorker(ForkJoinPool.java:1979)
at akka.dispatch.forkjoin.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:107)

"MySys-akka.actor.default-dispatcher-4" #362 prio=5 os_prio=0 tid=0x00007f55402e0000 nid=0x184 waiting on condition [0x00007f54445da000]
java.lang.Thread.State: WAITING (parking)
at sun.misc.Unsafe.park(Native Method)
- parking to wait for <0x00000000e4b5b1f0> (a akka.dispatch.ForkJoinExecutorConfigurator$AkkaForkJoinPool)
at akka.dispatch.forkjoin.ForkJoinPool.scan(ForkJoinPool.java:2075)
at akka.dispatch.forkjoin.ForkJoinPool.runWorker(ForkJoinPool.java:1979)
at akka.dispatch.forkjoin.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:107)

"MySys-akka.actor.default-dispatcher-3" #361 prio=5 os_prio=0 tid=0x00007f55402df000 nid=0x183 waiting on condition [0x00007f5539774000]
java.lang.Thread.State: WAITING (parking)
at sun.misc.Unsafe.park(Native Method)
- parking to wait for <0x00000000e4b5b1f0> (a akka.dispatch.ForkJoinExecutorConfigurator$AkkaForkJoinPool)
at akka.dispatch.forkjoin.ForkJoinPool.scan(ForkJoinPool.java:2075)
at akka.dispatch.forkjoin.ForkJoinPool.runWorker(ForkJoinPool.java:1979)
at akka.dispatch.forkjoin.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:107)

"MySys-akka.actor.default-dispatcher-2" #360 prio=5 os_prio=0 tid=0x00007f55402de800 nid=0x182 waiting on condition [0x00007f5440f31000]
java.lang.Thread.State: WAITING (parking)
at sun.misc.Unsafe.park(Native Method)
- parking to wait for <0x00000000e4b5b1f0> (a akka.dispatch.ForkJoinExecutorConfigurator$AkkaForkJoinPool)
at akka.dispatch.forkjoin.ForkJoinPool.scan(ForkJoinPool.java:2075)
at akka.dispatch.forkjoin.ForkJoinPool.runWorker(ForkJoinPool.java:1979)
at akka.dispatch.forkjoin.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:107)

"MySys-scheduler-1" #359 prio=5 os_prio=0 tid=0x00007f55402dd800 nid=0x181 waiting on condition [0x00007f54440d5000]
java.lang.Thread.State: TIMED_WAITING (sleeping)
at java.lang.Thread.sleep(Native Method)
at akka.actor.LightArrayRevolverScheduler.waitNanos(LightArrayRevolverScheduler.scala:85)
at akka.actor.LightArrayRevolverScheduler$$anon$4.nextTick(LightArrayRevolverScheduler.scala:265)
at akka.actor.LightArrayRevolverScheduler$$anon$4.run(LightArrayRevolverScheduler.scala:235)
at java.lang.Thread.run(Thread.java:748)

最佳答案

如果在构造新的 ActorSystem 时没有传递任何配置,则将使用根配置(即 akka key 内的所有内容)

configuration section of the akka docs建议您在同一应用程序中通过使用单独的配置专门初始化两个不同的 Actor 系统来初始化它们。

val config = ConfigFactory.load()
val system1 = ActorSystem("MySys", config.getConfig("MySys"))
val system2 = ActorSystem("my-app", config.getConfig("my-app"))

如果您无法影响第一个系统的创建方式,我建议您在 MySys 的配置中使用默认的 akka 区域,然后为应用程序所需的配置命名空间。

关于java - 在另一个库中配置ActorSystem,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56734343/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com