scala - Declaring Actor state variables as mutable ones -
i new akka framework , concurrency concepts. , akka docs, understood 1 message in actor mailbox processed @ time. single thread processing actor's state @ time. , doubt that, declaring actor state/data variable mutable - 'var'(only when 'val' doesn't fit), not cause inconsistent actor states in case of concurrency. using scala development. in following master actor, details of workers stored in mutable variable 'workers'. problem concurrency?
class master extends persistentactor actorlogging { ... private var workers = map[string, workerstate]() ... }
i think doing fine. said, 1 of fundamental guarantees of akka actors single actor handling 1 message @ time, there not inconsistent actor states.
akka actors conceptually each have own light-weight thread, shielded rest of system. means instead of having synchronize access using locks can write actor code without worrying concurrency @ all.
http://doc.akka.io/docs/akka/snapshot/general/actors.html
also, thing you're using var
instead of val
mutable map :)
Comments
Post a Comment