我正在尝试使用线程池来发起阻止请求。 问题是,每个请求都会阻塞整个池,并且项目将按顺序进行处理。 不知道这是否可能。有人请帮助Akka演员池用于阻止请求
city-dispatcher {
type = Dispatcher
executor = "thread-pool-executor"
thread-pool-executor {
fixed-pool-size = 16
}
throughput = 100
}
而Java
Props props = Props.create(CityDataProcessorActor.class, psRespHolder).withDispatcher("akka.actor.city-dispatcher");
SmallestMailboxPool pool = new SmallestMailboxPool(10);
ActorRef cityRequestActorPool = actorSystem.actorOf(pool.props(props), "city-request-route");
for (String city : citiesArray) {
Future<Object> future = Patterns.ask(cityRequestActorPool, new CityCommand(city.trim()), timeout);
Object results = Await.result(future, duration);
log.info(results.toString());
}
'对象结果= Await.result(未来,持续时间);'这段代码是阻塞。直到结果被声明为止,你的'for'循环才会前进。 –