#1272 A question regarding Actor

rosarinjroy Thu 28 Oct 2010

I have the following questions regarding the Actor and Actor.locals. Could someone please help me?

  • Once an actor is created, is it guaranteed that the Actor instance will be executed in the same thread every time?
  • If the answer to above question is "no", will Actor.locals return the same map immaterial of which thread context the Actor is running in? Or it will return an empty map every time the actor is executed the first time in a new thread?

I went through the Actor.java source code and felt like Actor local is the same as ThreadLocal. Please help me to understand this concept better.

Thank you.

brian Thu 28 Oct 2010

There is no guarantee that an Actor will always be processed on the same thread. Rather it is better to think of an actor like a worker who gets assigned to a thread from a thread-pool when it has work to do (receive a message).

Actor locals are essentially just state that travels with the actor each time it is assigned to a thread (during the exection of receive, the locals are stored in a thread local).

If you want to dive into the implementation, look at Actor.java _work.

rosarinjroy Thu 28 Oct 2010

Brian: Thank you for your clarification. And pointing me to the right reference.

Login or Signup to reply.