/**
*分段批量处理
*看看什么是垃圾代码
*/
public void saveRepaystatList(List tiuRepaystatList) {
SqlMapExecutor executor = getSqlMapExecutor();
try {
int size = tiuRepaystatList.size();
int section = 500;
int count = size / section + 1;
long totleTime = 0;
System.out.println("个人担保信息数据开始批量保存---------------------");
for (int m = 0;
m < count;
m++) {
System.out.println("开始保存第 " + m + " 部分数据" + "本次执行 " + m* section + "-----"+ ((m + 1) * section > size ? size : (m + 1) * section)+ " 数据");
long startTime = System.currentTimeMillis();
executor.startBatch();
for (int i = m * section;
i < ((m + 1) * section > size ? size: (m + 1) * section);
i++) {
TiuRepaystat tiuRepaystat = (TiuRepaystat) tiuRepaystatList.get(i);
executor.insert("insertTiuRepaystat", tiuRepaystat);
}
executor.executeBatch();
long endTime = System.currentTimeMillis();
totleTime = totleTime + (endTime - startTime);
System.out.println("本次执行共耗费时间 " + (endTime - startTime) + " ms");
}
System.out.println("个人24月还款状态保存结束----------共花费时间" + totleTime+ "-----------");
} catch (SQLException e) {
throw new DaoException("个人24月还款状态保存失败.Cause: " + e, e);
}
}
【对比一下】
/**
*看看对比一下
*/if (tiuEmpList.isEmpty()) {
return;
}
Iterator iter = tiuEmpList.iterator();
int count = 0;
while (iter.hasNext()) {
if (count == 0) {
executor.startBatch();
}
TiuEmp tiuEmp = (TiuEmp)iter.next();
tiuEmp.setCerttype(StringUtils.defaultIfEmpty(CROSS_REFERENCES.get(CTFC_NAME+ tiuEmp.getCerttype()), "X"));
executor.insert("insertTiuEmp", tiuEmp);
if (count == 500 || !iter.hasNext()) {
executor.executeBatch();
count = 0;
}
}
推荐阅读
- Java|Java基础——数组
- 人工智能|干货!人体姿态估计与运动预测
- java简介|Java是什么(Java能用来干什么?)
- Java|规范的打印日志
- Linux|109 个实用 shell 脚本
- 程序员|【高级Java架构师系统学习】毕业一年萌新的Java大厂面经,最新整理
- Spring注解驱动第十讲--@Autowired使用
- SqlServer|sql server的UPDLOCK、HOLDLOCK试验
- jvm|【JVM】JVM08(java内存模型解析[JMM])
- 技术|为参加2021年蓝桥杯Java软件开发大学B组细心整理常见基础知识、搜索和常用算法解析例题(持续更新...)