Programming with Scala threads
Scala's threading API uses Java threads. In fact, the wrapper is very thin and they work almost exactly the same way that Java threads do. This is probably the most straightforward way of carrying out parallelism in Scala if you are already familiar with threading APIs in other languages. However, Scala also extends the Java threading API in numerous ways that make it even more convenient to work with. We will look into those ways in this section.
A simple Scala thread example
Let's see a very simple example of programming with Scala threads. The following is the simplest example I could come up with; however, it is also the one that manages to illustrate the most basic uses of the old Java threading model. The following example runs three threads, each of which gets a specific message to print a standard output. The threads are then run in parallel, each printing its message and pausing for one second between printing statements. This will continue...