package com.example.demo;
import java.util.ArrayList;
import java.util.List;
public class BatchTest {
/**
* 批量写入
*
* @param args
*/
public static void main(String[] args) {
List 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 reterList() {
List list = new ArrayList<>();
for (int i = 0; i < 103; i++) {
list.add(i + "");
}
return list;
}
}
标签:batchNum,Java,批量,int,list,写入,total,List,bak
来源: https://www.cnblogs.com/coderdxj/p/13872335.html