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

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

spring boot的測試問題,求解答

spring boot的測試問題,求解答

HUWWW 2019-02-19 06:52:32
@RunWith(SpringJUnit4ClassRunner.class)@WebAppConfiguration@Transactional@SpringApplicationConfiguration(Application.class)public class Main { static Log logger = LogFactory.getLog(Main.class); @Test public void test() { ExecutorService fixedThreadPool = Executors.newFixedThreadPool(11); for (int i = 0; i < 10; i++) { fixedThreadPool.execute(new Runnable() { @Override public void run() { System.out.println("a"); } }); } System.out.println("b"); } 為什么輸出結(jié)果是ab,而不是10個(gè)a和1個(gè)b
查看完整描述

1 回答

?
慕碼人8056858

TA貢獻(xiàn)1803條經(jīng)驗(yàn) 獲得超6個(gè)贊

單元測試運(yùn)行結(jié)束后會強(qiáng)制退出進(jìn)程。所以剩下的線程并不會執(zhí)行。你可以使用下面的示例等待所有任務(wù)執(zhí)行完成。

ExecutorService executorService = Executors.newFixedThreadPool(11);
CountDownLatch latch = new CountDownLatch(10);
for (int i = 0; i < 10; i++) {
    final int v = i;
    executorService.execute(() -> {
        latch.countDown();
        System.out.println(v + " - a");
    });
}
System.out.println("b");
try {
    // 等待所有任務(wù)結(jié)束
    latch.await();
} catch (InterruptedException e) {
    e.printStackTrace();
}
查看完整回答
反對 回復(fù) 2019-03-01
  • 1 回答
  • 0 關(guān)注
  • 448 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號

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