If you're interested in functional programming, you might also want to checkout my second blog which i'm actively working on!!

Monday, March 15, 2010

SCALA actors

Threads are still a complex topic to get right in Java due do
-racing conditions
-dead locks
-shared state

Scala borrowed the Actor model from Erlang where messages are send to an Actor and the Actor decides based on the Message send (case) if it will process them

I wrote some simple SCALA classes in order to test Actors.

First i wrote a abstract class Job which implements a execute method.

Next i wrote 2 implementations PrintJob and SumJob which resp.
- prints a string
- print the total of a list of numbers

The JobActor itself handles 3 cases:
-case Any
-"exit" command

So to finally test the JobActor I wrote a little script which invokes the JobActor with several cases:

The output on my console is as expected:

No comments:

Post a Comment