第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

為什么 Spring Boot 中使用 ExecutorCompletionService

為什么 Spring Boot 中使用 ExecutorCompletionService

守著一只汪 2023-12-30 16:13:35
我使用 spring boot 版本 2.1.9.RELEASE 和 Java 1.8,并且有兩個 lang 運行進程,我想并行啟動它們。因此我決定使用線程。當我啟動 sumResult 方法時,第二個線程首先啟動,第一個線程等待,直到第二個線程完成。為什么這兩個線程不同時啟動或至少在短時間內(nèi)啟動?private void sumResult(String year, String month, String day) throws     ExecutionException, InterruptedException {         ExecutorCompletionService<Boolean> completionService = new          ExecutorCompletionService<>(Executors.newCachedThreadPool());         // First thread         mut.initialise(year, month, day);         boolean mutCompleted = completionService.submit(               ()-> mut.sum(),true).get();         // Second thread         apt.initialise(year, month, day);         boolean aptCompleted = completionService.submit(              ()-> apt.sum(), true).get();         // On completion of both thread         if(mutCompleted && aptCompleted ){              mixAndPrint();         }}
查看完整描述

1 回答

?
FFIVE

TA貢獻1797條經(jīng)驗 獲得超6個贊

get()因為您在提交第二個作業(yè)之前就阻止了第一個作業(yè)的調(diào)用。

submit
get
submit
get

如果你想讓它們并行運行,你需要這樣做

submit
submit
get
get


查看完整回答
反對 回復 2023-12-30
  • 1 回答
  • 0 關注
  • 134 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網(wǎng)微信公眾號