你们能否展示在 Akka 中限制消息的示例?
这是我的代码
object Program {
def main(args: Array[String]) {
val system = ActorSystem()
val actor: ActorRef = system.actorOf(Props[HelloActor].withDispatcher("akka.actor.my-thread-pool-dispatcher"))
val zzz : Function0[Unit] = () => {
println(System.currentTimeMillis())
Thread.sleep(5000)
}
var i: Int = 0
while (i < 100) {
actor ! zzz
i += 1
}
println("DONE")
// system.shutdown()
}
}
class HelloActor extends Actor {
def receive = {
case func : Function0[Unit] => func()
}
}
这是我的配置
akka {
actor {
my-thread-pool-dispatcher {
type = Dispatcher
executor = "thread-pool-executor"
thread-pool-executor {
task-queue-type = "array"
task-queue-size = 4
}
}
}
}
但是当我运行它时,它似乎是单线程的,因为我希望同时处理 4 条消息。
我在这里想念什么?