1
我有下面的代码块,稍微延迟调用两个请求。Akka调度
final ActorRef actor1 = getContext().actorOf(
ActorClass.props(context,
"actor1");
futures.add(ask(actor1 , msg1, t));
final ActorRef actor2 = getContext().actorOf(
ActorClass.props(context,
"actor2");
futures.add(Patterns.after(Duration.create(10000, TimeUnit.MILLISECONDS),
getContext().system().scheduler() ,
getContext().dispatcher(), ask(actor2,msg2,t)));
在actor1和actor2中,我调用了一个REST请求,它返回一个cookie以及响应消息。我的意图是延迟发送与actor2对应的REST请求。然而,我从日志中观察到的是,请求是从两个参与者立即发送的,并且只有响应处理(两个期货之间)延迟了10秒。这是Akka调度程序的预期行为吗?如果我想在上述情况下延迟两个参与者之间的请求启动,我可以使用Thread.sleep吗? (我读过的地方不建议在akka actor中使用Thread.sleep)。欣赏投入。