Student table
一个学生表
excel表
Student实体
@Data
public class Student {
private int id;
private int studentId;
private int teacherId;
private String studentName;
private int studentAge;
private int studentSex;
}
StudentMapper
void studentAdd(int id,int studentId,int teacherId,String studentName,int studentAge,int studentSex);
<insert id="studentAdd" >
insert into student values(#{arg0},#{arg2},#{arg1},#{arg3},#{arg4},#{arg5})
</insert>
Service
public void saveExcelStudent(List<Student> studentList) throws InterruptedException {
//一个线程处理100条数据
int count = 100;
//数据集合大小
int listSize = studentList.size();
//开启的线程数
int threadSize = (listSize / count) +1;
//存放每个线程的执行数据
List<Student> newList = null;
Integer mun = 0;
ExecutorService executor = Executors.newFixedThreadPool(threadSize);
CountDownLatch begin = new CountDownLatch(1);
CountDownLatch end = new CountDownLatch(threadSize);
//循环创建线程
for(int i = 0;i < threadSize;i++){
//startIndex是一个线程的第一个元素在studentList的索引,endIndex是一个线程最后一个元素在studentList的索引
//newList 将一个线程在studentList对应的student放入newList
if((i + 1) == threadSize){
int startIndex = (i * count);
int endIndex = studentList.size()