我有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
}
}
}
任何输入都受到高度赞赏
答案 0 :(得分:0)
我认为你可能最好创建2个actor类型:consumer(并行运行)和coordinator(它接受12个线程任务并将它们传递给消费者)。协调员将等待消费者完成,然后运行下一批。
请参阅此答案以获取代码示例:Can Scala actors process multiple messages simultaneously?
如果做不到这一点,你可以用类似的方式使用期货。