Modern languages, like Fantom and Scala are ditching the Java
like Threading model for an Actor based model. So is there
something wrong with Threads? Why do we need actors? Turns out
that it’s really simple. There is nothing wrong with threads in
java. Its just that variables are shared between threads. Each
thread can see and modify the same variables. To prevent
accidental corruption you need to “synchronize” blocks of your
code so only one thread can access it at a time. With actors,
its sort of like each thread gets its own variables.(its own
state). Each actor can only see and modify these. Remember
Object Oriented encapsulation? – Where each function in a class
can only see and modify variables(if its private) in its class?
Think of Actors as applying the same principles to Threads. Its
a new Level of encapsulation for Threads. Imagine you and your
friend decide to write this post down on a piece of paper, each
willing to write half of it. The problem is, you have a shared
paper to write down to. Now i