The thread pool used by the Scala actors may not work liike you think it should, causing actors to starve.
To see why, lets first define a utility method to measure how long an actor takes to act. We take a timestamp, then create an actor that just prints to the console how many milliseconds passed since the timestamp
import scala.actors.Actor._
def timeActor = {
val start = System.currentTimeMillis
actor {println("Took: " + (System.currentTimeMillis - start))}
}
Testing it:
scala> timeActor
Took: 2
res49: scala.actors.Actor = scala.actors.Actor$$anon$1@18e905
We see the actor ran within 2 milliseconds.
Now lets throw some more actors that just block and see how much the actor took: