当前位置: 首页 > 工具软件 > JActor > 使用案例 >

Jactor介绍

越宣
2023-12-01

   网上可以找到作者Jactor的源码:

作者对actor的解释:

Actors are objects which send messages to each other and which process only one message at a time. Messages are
 
      either requests or responses. When an actor sends a request to another actor, it expects to receive a single
 
      response unless an exception has been thrown.

       Actors 是对象之间能够相互发送消息而且一次只能处理一个消息,消息就是一个请求或者一个响应。

       当一个actor发送一个请求给另外一个actor的时候,它期望接收一个响应消息除非抛出了异常。

   When an actor sends a message it provides a callback to handle the response. The callback may be invoked either
  immediately or later. After sending a message, an actor may send additional messages or return control, at which
   point it may receive other requests or pending responses.

   当actor发送一个消息的时候,它提供了一个回调函数来处理响应消息。回调函数有可能立即执行也有可能稍后执行。

发送一个消息后,actor可以发送更多的消息或者接收其他的请求或者等待响应

    An actor typically interleaves the processing of multiple requests. To process a request to completion, an actor may
  need to send requests to other actors (in series or parallel) and process the responses to those requests. Actors
  process requests and responses as they are received whenever the actor is not busy processing a message. There is no
 way to block incoming requests. Actors are thread-safe, but message processing is not atomic.

  一个actor通常交错处理多个请求。为了处理一个完整性的请求,一个actor需要发送请求给其他的(串联或并联)actor 而且 需要对这些响应做处理。

  当actors不忙与处理一个消息的时候,无论何时会 处理请求和回复。它不会阻断请求。actor是线程安全的,但消息处理不是原子性的。

Some actors are asynchronous. Requests sent to an asynchronous actor are processed on a different thread. Actors which
  perform heavy computation or which do I/O should be asynchronous. Asynchronous actors play an important role in
  vertical scalability, allowing a program to make effective use of multiple hardware threads. But care should be used,
  as asynchronous message passing tends to be slow.

  一些actor是异步的,发送一个请求给一个异步的actor时,处理会在一个不同的线程上。actor在执行大量的计算或者耗io的操作应当异步执行。

异步的actor在垂直可扩展性方面扮演了重要角色,允许程序有效的使用多线程。在使用的时候需要注意,应当是一个较慢的短暂异步消息。

 类似资料: