ExecutorService es = Executors.newFixedThreadPool(THREADPOOLSIZE+1); while(true){ long startTime2 = System.currentTimeMillis(); numIids = getIds(batchId, LIMITSIZE); if (numIids == null || numIids.isEmpty()) { break; } int i = 0; int batchSize = numIids.size() / THREADPOOLSIZE; if (numIids.size() > THREADPOOLSIZE) { for (i = 0; i < THREADPOOLSIZE; i++) { List<Long> subList = numIids.subList(i * batchSize, ((i + 1) * batchSize)); es.submit(() -> { try { compute(batchId, subList); } catch (Exception e) { e.printStackTrace(); } }); } } if (i * batchSize < numIids.size()) { List<Long> subList = numIids.subList(i * batchSize, numIids.size()); es.submit(() -> { try { compute(batchId, subList); } catch (Exception e) { e.printStackTrace(); } }); } 我想在這里實(shí)現(xiàn)等待上面所有子線程完成所有任務(wù),然后向下執(zhí)行(不關(guān)閉線程池中的線程,讓這些線程重復(fù)使用) } es.shutdown(); awaitTerminationQuietly(es); }
ExecutorService怎樣不用shutdown,awaitTermination實(shí)現(xiàn)主線程等
慕運(yùn)維8079593
2019-03-22 15:15:23