Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/scala/19.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Scala 阿克卡线程调整_Scala_Akka - Fatal编程技术网

Scala 阿克卡线程调整

Scala 阿克卡线程调整,scala,akka,Scala,Akka,我有100个线程,一次只需要处理12个线程。这些线程完成后,必须处理其他12个线程,以此类推,但它只处理前12个设置线程,然后在此之后终止。 我的逻辑是: class AkkaProcessing extends Actor { def receive = { case message: List[Any] => var meterName = message(0) // It Contains only 12 threads , it process them and termi

我有100个线程,一次只需要处理12个线程。这些线程完成后,必须处理其他12个线程,以此类推,但它只处理前12个设置线程,然后在此之后终止。
我的逻辑是:

 class AkkaProcessing extends Actor {
  def receive = {
case message: List[Any] =>
var meterName = message(0)  // It Contains only 12 threads , it process them and terminates. Am unable to get remaining threads

val sqlContext = message(1).asInstanceOf[SQLContext]
val FlagDF = message(2).asInstanceOf[DataFrame]
        {

               All the business logic here
          }

       context.system.shutdown()
    }
  }
}
object Processing {
  def main(args: Array[String]) = {
  val rawBuff = new ArrayBuffer[Any]()
  val actorSystem = ActorSystem("ActorSystem") // Creating ActorSystem 
  val actor = actorSystem.actorOf(Props[AkkaProcessing].withRouter(RoundRobinPool(200)), "my-Actor")
  implicit val executionContext = actorSystem.dispatchers.lookup("akka.actor.my-dispatcher")

  for (i <- 0 until meter_list.length) {

    var meterName = meter_list(i)     // All 100 Meters here

    rawBuff.append(meterName, sqlContext, FlagDF)
    actor ! rawBuff.toList
   }
  }
  }
AkkaProcessing类扩展了Actor{ def接收={ 案例消息:列表[任何]=> var meterName=message(0)//它只包含12个线程,它处理它们并终止。我无法获取剩余的线程 val sqlContext=message(1).asInstanceOf[sqlContext] val FlagDF=消息(2).asInstanceOf[DataFrame] { 这里的所有业务逻辑 } context.system.shutdown() } } } 对象处理{ def main(参数:数组[字符串])={ val rawBuff=新阵列缓冲[任何]() val actorSystem=actorSystem(“actorSystem”)//正在创建actorSystem val actor=actorSystem.actorOf(Props[AkkaProcessing].withRouter(RoundRobinPool(200)),“我的actor”) 隐式val executionContext=actorSystem.dispatchers.lookup(“akka.actor.my dispatcher”)
对于(i我认为您最好创建两种参与者类型:consumer(并行运行)和coordinator(将12个线程任务传递给consumer)。coordinator将等待consumer完成,然后运行下一批

有关代码示例,请参见此答案:

如果做不到这一点,你可以用类似的方式使用期货