請問你們可以在阿卡展示節流消息的例子嗎?如何在Akka中節流消息(2.1.2)?
這裏是我的代碼
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個消息,在被處理同時。
我在這裏錯過了什麼?