Java 同时创建多个参与者

Java 同时创建多个参与者,java,graph,parallel-processing,akka,Java,Graph,Parallel Processing,Akka,我正在使用AKKA框架及其JavaAPI来创建一个actor系统。以下是演员的要点。参与者负责处理图形中的节点。对于图中同一级别上的节点,处理可以并行完成,因此当达到这样一个级别时,我需要并行生成参与者 SupervisorActor extends Actor { // if (msg instanceOf something) // spawn child actor for every level in a graph childActor.tell(node, getself());

我正在使用AKKA框架及其JavaAPI来创建一个actor系统。以下是演员的要点。参与者负责处理图形中的节点。对于图中同一级别上的节点,处理可以并行完成,因此当达到这样一个级别时,我需要并行生成参与者

SupervisorActor extends Actor  {
// if (msg instanceOf something)
// spawn child actor for every level in a graph
childActor.tell(node, getself());

How do I send messages to two childActors here when I have two nodes at the same level?

}

参与者异步通信,因此您可以创建两个参与者并调用tell两次,以向每个参与者发送消息,他们将同时处理该消息

如果您选择以下选项:

ActorRef child1 = getContext().actorOf(Props.create(MyActor.class), "child1");
ActorRef child2 = getContext().actorOf(Props.create(MyActor.class), "child2");
child1.tell(msg1, getself());
child2.tell(msg2, getself());

参与者child1和child2将同时创建并处理一条消息。

假设您要求创建同一参与者的多个实例

您可以在配置文件中定义需要多少个actor实例

akka {
 /my-service {
  router = round-robin-pool // strategy how message will be served
  nr-of-instances = 3} // here you can define the number of instance
}

参与者异步通信,因此您可以创建两个参与者并调用tell两次,向每个参与者发送消息,他们将同时处理消息。您是否可以使用伪代码进行解释?好的,我在下面回答