The actor model of Scala's Akka (top)

Source: Internet
Author: User

Original address: http://my.oschina.net/jingxing05/blog/287213

explicit parallelism and concurrency

Look at two pictures.

Parallel parallelism

Concurrent concurrency

The key point is that there is no communication and interaction between multiple tasks.

AC: Shared memory (Lock semaphore) message-driven Interaction: competition

The same code in a sequence runs concurrently in parallel with multiple copies ... Multiple lanes

And when the code of this sequence is divided into several separate execution segments, the individual segments can be executed simultaneously and generate communication

Multiple cars on one road can overtake

Multithreading is parallel, but not necessarily concurrent, if there is no interaction

No manipulation of shared variables, no need to consider the so-called concurrency problem

Reference http://wangcong.org/blog/archives/2054

Actor Model elements of the Actor modelActor-based systems where the actor is the smallest abstract unit, like object to oop an actor encapsulates state and behavior outside the actor to get its state, field, execution method, and actor interaction can only be through the message An actor has a mailbox mailbox, which sends the externally sent message msg to the queue actor's lifetime is waiting for MSG, and then take out the messages in the mailbox to processThe organization view of actor modelThe actor system as a company, from top to bottom have a strict hierarchical relationship, the company's employees are person, is also actor an actor only a superior supervisor called Supervisor, is the actor of create this actor An actor may have more than one subordinate soldier, a real dirty-tired actor. An actor may have multiple siblings of siblings actorkey to developing the actor systemDelegate Delegate delegation ... To do more. The company boss can not take all the responsibility, his main job is to assign the company's work and supervise the department heads receive the task, or do their own work, or subdivide the task, and then assigned to their subordinates and supervise if the company has more levels, then continue above this supervisor's dirty activities at the bottom of the staff received fine-grained tasks , doing what he's best at.failure handling of actorNo one is perfect, the actor is impossible. 100% complete a task if the task fails, an actor suspends himself and his subordinates, and then sends a message telling his superiors that "I failed". When a supervisor receives a "failed" message from a subordinate, it can react as follows: Failure fails, so it's not too much of a relationship: keep the current state, resume the actor, continue working not successful Ah, then redo it again: Reset the status, restart the actor no chance, failed you will roll. Dismiss subordinate: Close End the actor this matter I also can't decide, I ask my superior: report to the superior ActorSome additional features of the Actor model implemented by AkkaWhen instantiating an actor, returning an Actorref, which is equivalent to an email address, does not get the actor's state information through this actor model is a higher-level abstraction of threads, and eventually multiple actors running in Java threads may share a thread, which is guaranteed by Akka Actor's mailbox has a variety of implementations: Infinite variable mailbox with a priority mailbox and a custom implementation Akka does not have the actor scan the mailbox message an actor end (whether normal or very) MSG in its mailbox enters the Akka system's "Dead Mailbox de Ad Letter Mailbox "in

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.