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
-Job
-"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