We now know how to create an actor and send messages to it. Let’s get a feel for putting multiple actors to work. In Chapter 2, Division of Labor, we created a concurrent program to count primes in a range. In the example in Concurrent Computation of Prime Numbers, we used ExecutorService, Callable, and Future and filled up a little over a page with code. Let’s see how that example shapes up with Akka actors first in Java and then in Scala.
Given a number like 10 million, we divided the computation of primes into different ranges and distributed these ranges over several threads. Here we’re going to use actors. Let’s start with the actor’s onReceive method: