Scala - should ExecutorService be used for splitting work among the threads?

concurrency, scala

Solution

The pure Scala way

Scala's concurrency model is based around the Erlang actor model. It's a slightly different approach. To fully exploit Scala's concurrency, use something like Akka. The basic usage idea is fairly simple.

The most simple task is using a `Future`(an asynchronous action). Read more about this HERE. The Executors framework is not the approach you should take. There are quite a few options to achieve powerful multi-threaded| parallelisms in your Scala applications:

- Akka

- Lift actors(when using the Lift web framework).

- Finagle(The Twitter RPC framework).

- The default Scala actors library, DEPRECATED in Scala 2.10. Read more HERE.

The Scala/Java interoperability approach

Actors may be a drastic change to the way you are used to implementing concurrency, and Java doesn't have shortcomings there. So you can still use the Executor framework for multi-threading in Scala applications.

It means you will rely almost entirely on native Java concurrency structures, but it gets you there with having to change much. Read more on how to do that in Scala HERE.

Problem

Coming from a Java background, a problem of splitting multiple tasks amongst multiple threads can be easily using ExecutorService and submitting tasks through that interface. Would you say the same approach makes sense in Scala world? If so, is there a Scala version of that API? If no, what approach would you recommend? Actors seem to be a bit of an overkill, as I would envision them to be used for thread communication mostly...

Original source