JAVA批量提交和计算每批次批量提交的时间及最后消耗的总时间的测试用例

自己写的一个测试用例。记录在案。

package Junt;

import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Statement;

import com.whaty.platform.database.oracle.dbpool;

/**
 * @name:TestBatch.java
 * @desc:
 * @author:lizhuang
 * @createTime:2012-8-10 下午08:01:10
 */
public class TestBatch {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		testTime();
	}

	public static void testTime() {
		dbpool pool = new dbpool();
		Connection conn = pool.getConn();
		Statement ps = null;
		try {
			ps = conn.createStatement();
			long start= System.currentTimeMillis();
			for (int i = 0; i < 1; i++) {
				long starttime = 0;
				for (int j = 0; j < 1002; j++) {
					String sql = "UPDATE pe_bzz_examscore t  SET t.test_score=(select s.AVG_test_score from stat_study_summary s "
							+ "where s.student_id='ff8080813104436201311415f0bf1234' and s.batch_id='4028809929f2e6870129f2fd0c390009') " + "where t.student_id='ff8080813104436201311415f0bf1234';";
					ps.addBatch(sql);
					if (j == 1001) {
						ps.executeBatch();
						break;
					}
					if (j % 200 == 0 && j != 0) {
						starttime = System.currentTimeMillis();
						ps.executeBatch();
						long endtime = System.currentTimeMillis();
						long totTime = endtime - starttime;
						System.out.println("Using Time: " + totTime / 1000 + " sec\t" + totTime + " ms");
					}
				}

			}
			ps.close();
			conn.close();
			long end= System.currentTimeMillis();
			System.out.println("Total Time: " + (end-start) / 1000 + " sec");
			System.out.println("Total Time: " + (end-start) + " ms");
		} catch (SQLException e) {
			e.printStackTrace();
		}
		System.out.println("over....");
	}

}


控制台显示:

Using Time: 4 sec	4312 ms
Using Time: 4 sec	4251 ms
Using Time: 4 sec	4220 ms
Using Time: 4 sec	4235 ms
Using Time: 4 sec	4236 ms
Total Time: 21 sec
Total Time: 21271 ms
over....


为什么要批量提交?一次提交量过大,也占用太多带宽,效率上不是很理想,如果遇到10万级别以上数据,估计就宕机了。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值