Chapter 12. Asynchronous programming

 

This chapter covers

  • Scala, servlets, and mutable state
  • Using Futures for asynchronous programming
  • Using Akka Actors with Scalatra
  • Big data in Scalatra with Spark

Scala makes multicore, distributed, and asynchronous programming easier. Its focus on immutability, as well as associated libraries such as Akka, lower the conceptual burdens of concurrency management by making it easier to reason about your code. Why is this important?

Most other languages still rely on old-style concurrency management tools like locks and threads, which can be extremely difficult to use because they are non-deterministic. That is, you can’t necessarily reproduce your threading bugs when you want, because they can be the result of multiple threads interacting in strange and horrifying ways.

Older concurrency models were designed in an age of non-networked, single-core microcomputers, when building distributed systems was the exception rather than the norm. We now live in a very different world. New servers today typically have 32 or 64 cores, and high-performance applications are almost always built to run across a network. Scala stands out from the language crowd as a great choice for this new hardware and networking environment. This is one of the reasons that it’s being used by big organizations that need to build highly scalable distributed systems.

How does Scalatra fit into all this?

12.1. Exploring concurrency in Scalatra

12.2. Using Futures in Scalatra

12.3. Using Akka Actors from Scalatra

12.4. Using Scalatra for big data

12.5. Summary