exp*_*ert 2 scala akka scala-2.10
你们可以在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()
}
}
Run Code Online (Sandbox Code Playgroud)
这是我的配置
akka {
actor {
my-thread-pool-dispatcher {
type = Dispatcher
executor = "thread-pool-executor"
thread-pool-executor {
task-queue-type = "array"
task-queue-size = 4
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
但是当我运行它时,它似乎是单线程的,因为我希望同时处理4条消息.
我在这里错过了什么?
我没有看到问题标题和内容之间的联系.
这是一篇关于在Akka中限制消息的文章:
http://letitcrash.com/post/28901663062/throttling-messages-in-akka-2
但是,您似乎对您的actor一次只处理一条消息这一事实感到困惑.但这就是Akka演员的工作方式.它们具有单个邮件邮箱,并且它们在连续循环中一次只处理一条消息.
如果你想同时处理同一个工作处理单元的多个任务,我建议你看看路由器:
http://doc.akka.io/docs/akka/2.1.2/scala/routing.html
| 归档时间: |
|
| 查看次数: |
1657 次 |
| 最近记录: |