因机器性能影响,不同环境下5万条数据本地大概要10几分钟,开发环境大概5、6分钟、生产大概3、4分钟。
首先,假如我拿到了2万条数据,然后我对它进行一个分组,规定每组有多少个(我们这里是1000条,多了数据库会报一个值过多的错误),算出可以分为多少组
根据预先定义的最大线程数,如果超出最大线程数对其进行重新分组,然后决定创建多少个线程
本次使用Oracle数据库,数据库表字段大概50个
本次使用场景:Excel大数据量上传
自己定义的service继承ISaveService
public interface AccountTypeService extends ISaveService<AccountTypeVO> {
WtrFileCheckVO insertAccountList(WtrFileCheckVO wtrFileCheckVO);
}
public interface ISaveService<T> {
/**
* 子线程批量保存方法
* @param list
* @param endFlag
* @param threadId
* @return
* @throws Exception
*/
Integer batchSave(List<T> list, MultiEndFlag endFlag, UUID threadId, String threadName) throws Exception;
}
//service实现类的方法
@Service
public class AccountTypeServiceImpl implements AccountTypeService {
private static final int BATCH_COUNT = 1000;//全局变量