`
nasizq
  • 浏览: 43753 次
  • 性别: Icon_minigender_1
  • 来自: 叶柏寿
社区版块
存档分类
最新评论

对比一下

    博客分类:
  • Java
 
阅读更多
/**
*分段批量处理
*看看什么是垃圾代码
*/
	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;
				}
			}

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics