akka.io调度程序配置异常

时间:2014-02-10 19:36:57

标签: java scala akka actor typesafe

在sbt 0.13项目中,我将以下内容放在application.conf

下的src/main/resources文件中

application.conf:

blocking-dispatcher {
type = PinnedDispatcher 

executor = "thread-pool-executor"
thread-pool-executor {
core-pool-size-min = 2
core-pool-size-factor = 2.0
core-pool-size-max = 10
}
throughput = 100
mailbox-capacity = -1
mailbox-type =""
}

现在当我创建演员时,我得到了异常:

object Main extends App {

  implicit val system =  ActorSystem()

  val fileReaderActor  = system.actorOf(Props(new FileReaderActor(fileName)).withDispatcher("blocking-dispatcher"), "fileReaderActor")

}

我得到了:

Exception in thread "main" akka.ConfigurationException: Dispatcher [blocking-dispatcher] not configured for path akka://default/user/fileReaderActor
    at akka.actor.LocalActorRefProvider.actorOf(ActorRefProvider.scala:714)
    at akka.actor.dungeon.Children$class.makeChild(Children.scala:191)
    at akka.actor.dungeon.Children$class.attachChild(Children.scala:42)
    at akka.actor.ActorCell.attachChild(ActorCell.scala:338)
    at akka.actor.ActorSystemImpl.actorOf(ActorSystem.scala:518)
    at Main$delayedInit$body.apply(Main.scala:14)
    at scala.Function0$class.apply$mcV$sp(Function0.scala:40)
    at scala.runtime.AbstractFunction0.apply$mcV$sp(AbstractFunction0.scala:12)
    at scala.App$$anonfun$main$1.apply(App.scala:71)
    at scala.App$$anonfun$main$1.apply(App.scala:71)
    at scala.collection.immutable.List.foreach(List.scala:318)
    at scala.collection.generic.TraversableForwarder$class.foreach(TraversableForwarder.scala:32)
    at scala.App$class.main(App.scala:71)
    at Main$.main(Main.scala:8)
    at Main.main(Main.scala)

我错过了什么?

2 个答案:

答案 0 :(得分:2)

首先,确保您的配置已加载:

System.out.println(system.settings());
// this is a shortcut for system.settings().config().root().render()

在此处详细了解:http://doc.akka.io/docs/akka/2.2.3/general/configuration.html#Logging_of_Configuration

其次,以下配置并不合理:

blocking-dispatcher {
    type = PinnedDispatcher 

    executor = "thread-pool-executor"
    thread-pool-executor {
        core-pool-size-min = 2 <----- Since you're using a PinnedDispatcher, it only uses 1 thread
        core-pool-size-factor = 2.0 <----- same here
        core-pool-size-max = 10 <----- same here
    } <--- PinnedDispatcher will automatically make it 1 thread: https://github.com/akka/akka/blob/master/akka-actor/src/main/scala/akka/dispatch/PinnedDispatcher.scala#L27
    throughput = 100
    mailbox-capacity = -1
    mailbox-type =""
}

答案 1 :(得分:-1)

你必须像这样查找执行上下文调度程序

implicit val executionContext = system.dispatchers.lookup("blocking-dispatcher")

然后将此executionContext传递给ActorSystem。

来自文档的引用: If an ActorSystem is created with an ExecutionContext passed in, this ExecutionContext will be used as the default executor for all dispatchers in this ActorSystem. If no ExecutionContext is given, it will fallback to the executor specified in akka.actor.default-dispatcher.default-executor.fallback [1]

[1] http://doc.akka.io/docs/akka/snapshot/scala/dispatchers.html