我正在嘗試使用線程池來發起阻止請求。 問題是,每個請求都會阻塞整個池,並且項目將按順序進行處理。 不知道這是否可能。有人請幫助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'循環纔會前進。 –