@Component @Slf4j @Async public class ThreadSaveDigCategory { private static final int BATCH_COUTN = 1000; @Autowired private Mapper mapper; public Future<Boolean> saveDigCategoryDatas(List<DigCategoryData> digCategoryDataList){ //开始计时 long startTime = System.currentTimeMillis(); // mapper.saveDigCategoryData(digCategoryDataList); //数据分批处理 List<List<DigCategoryData>> batchList = BathProcessUtil.batchList(digCategoryDataList, BATCH_COUTN); for (List<DigCategoryData> batch : batchList){ mapper.saveDigCategoryData(batch); } //endTime long endTime = System.currentTimeMillis(); Calendar calendar = Calendar.getInstance(); calendar.setTimeInMillis(endTime-startTime); log.info("耗时: " + calendar.get(Calendar.MINUTE) + "分 " + calendar.get(Calendar.SECOND) + "秒 " + calendar.get(Calendar.MILLISECOND) + " 微秒" + "-" + "数据保存成功"); return new AsyncResult<>(true); } }
多线程返回计时问题代码案例
于 2023-11-08 17:25:42 首次发布