对比一下

/**
*分段批量处理
*看看什么是垃圾代码
*/
	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)