Re: [akka-user] Question about thread safe in actor
On Thu, May 15, 2014 at 1:43 AM, Leon Ma tutuf...@gmail.com wrote: By processes the messages one by one, do you mean My message B has to be wait until message A gets processed? They can't be executed in parallel? It's worth emphasizing -- the fact that they can't be executed in parallel is the entire *point* of the Actor model. That means that problems like the one you mention in your original post simply can't happen. Code is much easier to reason about, and avoids many of the common bugs of multi-threading. Actors think about parallelism very differently from ordinary threaded code. Instead of thinking about raw threads (and having to worry about them stepping on each other), you define a large number of Actors. Those Actors can be operating in parallel with each other, but any *given* Actor is effectively single-threaded. So you can be confident that an Actor is never processing multiple messages at any given time, while the system as a whole scales extremely well. -- Read the docs: http://akka.io/docs/ Check the FAQ: http://doc.akka.io/docs/akka/current/additional/faq.html Search the archives: https://groups.google.com/group/akka-user --- You received this message because you are subscribed to the Google Groups Akka User List group. To unsubscribe from this group and stop receiving emails from it, send an email to akka-user+unsubscr...@googlegroups.com. To post to this group, send email to akka-user@googlegroups.com. Visit this group at http://groups.google.com/group/akka-user. For more options, visit https://groups.google.com/d/optout.
Re: [akka-user] Question about thread safe in actor
Actors are thread safe inside them by definition. The actor has one mailbox and processes the messages one by one from it. We guarantee that fields are properly visible, even if the actor jumps around threads - no need for CHM in the actor On Thu, May 15, 2014 at 7:31 AM, Leon Ma tutuf...@gmail.com wrote: Hi, Assuming I have an actor which hold a map M And I will possibly do: 1, send message A to the actor 2. send message B to the actor When receiving messages, A will possibly be executed in thread 1 and B will possibly be executed in thread 2. Although A is triggered earlier than B ( sequence delivery is for sure), but B might be finished executing prior to A, right? Assuming in the receive method, I'll try to do something like find an entry from the map M, if not exist, then create one. Will I see any possible concurrent issues? should I use a thread safe map impl like TrieMap or ConcurrentHashMap to make sure the put operation is atomic like putIfAbsent? Thanks Leon -- Read the docs: http://akka.io/docs/ Check the FAQ: http://doc.akka.io/docs/akka/current/additional/faq.html Search the archives: https://groups.google.com/group/akka-user --- You received this message because you are subscribed to the Google Groups Akka User List group. To unsubscribe from this group and stop receiving emails from it, send an email to akka-user+unsubscr...@googlegroups.com. To post to this group, send email to akka-user@googlegroups.com. Visit this group at http://groups.google.com/group/akka-user. For more options, visit https://groups.google.com/d/optout. -- Cheers, Konrad 'ktoso' Malawski hAkker - Typesafe, Inc http://www.scaladays.org/ -- Read the docs: http://akka.io/docs/ Check the FAQ: http://doc.akka.io/docs/akka/current/additional/faq.html Search the archives: https://groups.google.com/group/akka-user --- You received this message because you are subscribed to the Google Groups Akka User List group. To unsubscribe from this group and stop receiving emails from it, send an email to akka-user+unsubscr...@googlegroups.com. To post to this group, send email to akka-user@googlegroups.com. Visit this group at http://groups.google.com/group/akka-user. For more options, visit https://groups.google.com/d/optout.
Re: [akka-user] Question about thread safe in actor
By processes the messages one by one, do you mean My message B has to be wait until message A gets processed? They can't be executed in parallel? Thanks Leon 在 2014年5月14日星期三UTC-7下午10时34分45秒,Konrad Malawski写道: Actors are thread safe inside them by definition. The actor has one mailbox and processes the messages one by one from it. We guarantee that fields are properly visible, even if the actor jumps around threads - no need for CHM in the actor On Thu, May 15, 2014 at 7:31 AM, Leon Ma tutu...@gmail.com javascript:wrote: Hi, Assuming I have an actor which hold a map M And I will possibly do: 1, send message A to the actor 2. send message B to the actor When receiving messages, A will possibly be executed in thread 1 and B will possibly be executed in thread 2. Although A is triggered earlier than B ( sequence delivery is for sure), but B might be finished executing prior to A, right? Assuming in the receive method, I'll try to do something like find an entry from the map M, if not exist, then create one. Will I see any possible concurrent issues? should I use a thread safe map impl like TrieMap or ConcurrentHashMap to make sure the put operation is atomic like putIfAbsent? Thanks Leon -- Read the docs: http://akka.io/docs/ Check the FAQ: http://doc.akka.io/docs/akka/current/additional/faq.html Search the archives: https://groups.google.com/group/akka-user --- You received this message because you are subscribed to the Google Groups Akka User List group. To unsubscribe from this group and stop receiving emails from it, send an email to akka-user+...@googlegroups.com javascript:. To post to this group, send email to akka...@googlegroups.comjavascript: . Visit this group at http://groups.google.com/group/akka-user. For more options, visit https://groups.google.com/d/optout. -- Cheers, Konrad 'ktoso' Malawski hAkker - Typesafe, Inc http://www.scaladays.org/ -- Read the docs: http://akka.io/docs/ Check the FAQ: http://doc.akka.io/docs/akka/current/additional/faq.html Search the archives: https://groups.google.com/group/akka-user --- You received this message because you are subscribed to the Google Groups Akka User List group. To unsubscribe from this group and stop receiving emails from it, send an email to akka-user+unsubscr...@googlegroups.com. To post to this group, send email to akka-user@googlegroups.com. Visit this group at http://groups.google.com/group/akka-user. For more options, visit https://groups.google.com/d/optout.
Re: [akka-user] Question about thread safe in actor
No. This is inherent to how the actor model is defined. Thanks to this youre safe from races inside the actor. -- Konrad 'ktoso' Malawski On 15 May 2014 07:43, Leon Ma tutuf...@gmail.com wrote: By processes the messages one by one, do you mean My message B has to be wait until message A gets processed? They can't be executed in parallel? Thanks Leon 在 2014年5月14日星期三UTC-7下午10时34分45秒,Konrad Malawski写道: Actors are thread safe inside them by definition. The actor has one mailbox and processes the messages one by one from it. We guarantee that fields are properly visible, even if the actor jumps around threads - no need for CHM in the actor On Thu, May 15, 2014 at 7:31 AM, Leon Ma tutu...@gmail.com wrote: Hi, Assuming I have an actor which hold a map M And I will possibly do: 1, send message A to the actor 2. send message B to the actor When receiving messages, A will possibly be executed in thread 1 and B will possibly be executed in thread 2. Although A is triggered earlier than B ( sequence delivery is for sure), but B might be finished executing prior to A, right? Assuming in the receive method, I'll try to do something like find an entry from the map M, if not exist, then create one. Will I see any possible concurrent issues? should I use a thread safe map impl like TrieMap or ConcurrentHashMap to make sure the put operation is atomic like putIfAbsent? Thanks Leon -- Read the docs: http://akka.io/docs/ Check the FAQ: http://doc.akka.io/docs/akka/ current/additional/faq.html Search the archives: https://groups.google.com/ group/akka-user --- You received this message because you are subscribed to the Google Groups Akka User List group. To unsubscribe from this group and stop receiving emails from it, send an email to akka-user+...@googlegroups.com. To post to this group, send email to akka...@googlegroups.com. Visit this group at http://groups.google.com/group/akka-user. For more options, visit https://groups.google.com/d/optout. -- Cheers, Konrad 'ktoso' Malawski hAkker - Typesafe, Inc http://www.scaladays.org/ -- Read the docs: http://akka.io/docs/ Check the FAQ: http://doc.akka.io/docs/akka/current/additional/faq.html Search the archives: https://groups.google.com/group/akka-user --- You received this message because you are subscribed to the Google Groups Akka User List group. To unsubscribe from this group and stop receiving emails from it, send an email to akka-user+unsubscr...@googlegroups.com. To post to this group, send email to akka-user@googlegroups.com. Visit this group at http://groups.google.com/group/akka-user. For more options, visit https://groups.google.com/d/optout. -- Read the docs: http://akka.io/docs/ Check the FAQ: http://doc.akka.io/docs/akka/current/additional/faq.html Search the archives: https://groups.google.com/group/akka-user --- You received this message because you are subscribed to the Google Groups Akka User List group. To unsubscribe from this group and stop receiving emails from it, send an email to akka-user+unsubscr...@googlegroups.com. To post to this group, send email to akka-user@googlegroups.com. Visit this group at http://groups.google.com/group/akka-user. For more options, visit https://groups.google.com/d/optout.