/**
* 批量插入
*/
List<List<ShipPlanLog>> partionList = new ArrayList<>();
if (param.size() >= 1000) {
partionList = Lists.partition(param, 1000);
} else {
partionList.add(param);
}
//多线程
CountDownLatch countDownLatch = new CountDownLatch(partionList.size());
ExecutorService executor = new ThreadPoolExecutor(
6,
6,
1,
TimeUnit.MICROSECONDS,
new ArrayBlockingQueue<>(6),
new ThreadFactoryBuilder().setNameFormat("create-log-%d").build()
);
for (List<ShipPlanLog> part: partionList) {
executor.submit(() -> {
shipPlanLogDao.insertBatchSomeColumn(part);
countDownLatch.countDown();
});
}
//关闭多线程
try {
countDownLatch.await();
} catch (InterruptedException e) {
LogUtil.error("create log insertBatchSomeColumn error", e);
throw new RuntimeException(e);
}finally {
executor.shutdown();
}
多线程批量插入
最新推荐文章于 2025-04-27 14:08:38 发布