package com.example.demo; import java.util.ArrayList; import java.util.List; public class BatchTest { /** * 批量写入 * * @param args */ public static void main(String[] args) { List<String> list = reterList(); int j = 0; //批量写入数据量 int batchNum = 10; int batchNum_bak = 10; int total = list.size(); while (true) { list.subList(j, j = j + batchNum).forEach(x -> { //执行业务逻辑 System.out.println(x); }); batchNum = ((total - j) % batchNum_bak) == 0 ? batchNum_bak : ((total - j) % batchNum_bak); if (j >= total) { return; } } } /** * 造数据 * * @return */ public static List<String> reterList() { List<String> list = new ArrayList<>(); for (int i = 0; i < 103; i++) { list.add(i + ""); } return list; } }