01: Scala Actors tutorial step by step

This assumes that you have set up Scala as per Setting up Scala IDE & using Maven plugins for Java developers.

Step 1: Add the “scala-actors” dependency to the pom.xml file.

Step 2: Scala’s primary concurrency construct is an actor. Actors are basically concurrent processes that communicate by exchanging messages. Create a simple “actor” based code as shown below.

The thread names are printed for clarity. The output will be as shown below.

Points to remember

1) The “scala-actors” library provides both asynchronous and synchronous sending of messages.

2) “!” is a send operator.

3) The “receive” method receives the message from the actors’ mailbox. Each actor has a mailbox to queue messages.

4) Actors are normal objects that can be created by instantiating subclasses of the “Actor” class.


800+ Java Interview Q&As Menu

Learn by categories on the go...
Learn by categories such as FAQs – Core Java, Key Area – Low Latency, Core Java – Java 8, JEE – Microservices, Big Data – NoSQL, Architecture – Distributed, Big Data – Spark, etc. Some posts belong to multiple categories.
Top