List分批处理结果,并在每批中开启一个线程
package com.cn.pro;
import java.util.ArrayList;
import java.util.List;
public class ListSplit{
public static void main(String[] args) {
//分批处理List集合,每100个处理一次,并开启一个线程
List<Object> list = new ArrayList<Object>();
for (int i = 0; i < 388; i++) {
list.add(i);
}
ListSplit.splitLi(list);
}
public static void splitLi(List<Object> dataList){
int pointsDataLimit = 100;
List<Object> newList = new ArrayList<Object>();
for(int i=0;i<dataList.size();i++){//分批次处理
newList.add(dataList.get(i));
if(pointsDataLimit == newList.size()||i == dataList.size()-1){
//printList(newList); //输出该批数据结果
new Thread() { //开启线程
public void run() {
System.out.println("开启线程…………");
}
}.start();
newList.clear();
}
}
}
public static void printList(List<Object> dataList){
for(Object str : dataList){
System.out.print(str + " -- ");
}
}
}