0
我有一個創建並在不同的PaaS部署應用以下方法:如何在所有`FutureTask`完成其計算後調用另一個方法?
private void deployModulesInPaaS() {
ExecutorService executor = Executors.newFixedThreadPool(listModules
.size());
ModuleParsed mod;
for (Iterator<ModuleParsed> iterator = listModules.iterator(); iterator
.hasNext();) {
mod = (ModuleParsed) iterator.next();
try {
switch (mod.getId_paas()) {
case 1:
GAEDeployer gaeDeployer = new GAEDeployer(mod.getId_paas(),
mod.getId_component(), "//whatever/path");
FutureTask<URI> gaeFuture = new FutureTask<URI>(gaeDeployer);
executor.execute(gaeFuture);
mod.setDeployedURI(gaeFuture.get());
break;
case 2:
AzureDeployer azureDeployer = new AzureDeployer(
"subscription", "path_certificate", "password",
"storageAccountName", "storageAccountKey");
FutureTask<URI> azureFuture = new FutureTask<URI>(
azureDeployer);
executor.execute(azureFuture);
mod.setDeployedURI(azureFuture.get());
break;
default:
System.out.println("The PaaS identifier of module "
+ mod.getId_component() + " is unknown.");
break;
}
} catch (InterruptedException e) {
e.printStackTrace();
} catch (ExecutionException e) {
e.printStackTrace();
}
}
}
我怎麼能再次呼籲所有FutureTask
已經完成了他們的計算的另一種方法? 我已閱讀約Command
模式和約Listener
,但我不確定這些是否是正確的,也不知道如何在這種情況下實現它們。