0

I have 100 threads, need to process only 12 threads at a time not more than that. After completion of these threads other 12 have to be processed and so on but it's processing only first 12 set threads then it terminates after that.
Here is my Logic :

 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
   }
  }
  }

Any Inputs highly appreciated

Abhishek
  • 25
  • 5

1 Answers1

0

I think you might be best to create 2 actor types : consumer (which run in parallel) and coordinator (which takes the 12 thread tasks and passes them to the consumers). The coordinator would wait for the consumers to finish and then run the next batch.

See this answer for a code example: Can Scala actors process multiple messages simultaneously?

Failing that, you could just use Futures in a similar manner.

jsdeveloper
  • 3,945
  • 1
  • 15
  • 14