Hibernate插入数据效率测试

硬件配置:

4G内存、CPUi3-2.3

数据库SQL2008


 

package com.pan.test;



import org.hibernate.Session;

import org.hibernate.Transaction;



import com.pan.bean.Student;

import com.pan.uitl.HibernateSessionFactory;



public class Test {



	/**

	 * @param args

	 */

	public static void main(String[] args) {

		// TODO Auto-generated method stub



		open();

		

	}

	

	private static void open(){

		

		//100 条数据521-689

		//1000条数据 8193 

		

		//分任务之后10个线程 6997-6698

		//100个线程 每个线程10次任务 - 2798

		

		//100个线程 测试 每个10条任务 6701

		

		//10000条数据 63899 CPU 22% 左右94876-95361

		//1000个线程 10个任务 71344

		

		//1000条数据分任务测试

		

		//1000条分为10次任务

		

		

		

		 Session session = HibernateSessionFactory.getSession();

		

		long startTime = System.currentTimeMillis();

		for(int i=0;i<1000;i++){

			

			Thread th=new MyThread(session, 100);

			th.setPriority(Thread.MAX_PRIORITY);

			th.run();



			

		}

		

		long endTime = System.currentTimeMillis();

		

		

		session.close();

		

		System.out.println(endTime-startTime);

		

	}



}



class MyThread extends Thread{



	private Session session;

	private int size;

	public MyThread(Session session,int size){

		this.session=session;

		this.size=size;

	}

	

	@Override

	public void run() {

	

		for(int i=0;i<size;i++){

			Transaction transaction = session.beginTransaction();

			Student student=new Student();

			student.setAddress("电视剧付款后大厦尽快发货上岛咖啡还是打飞机客户端");

			student.setMsn("[email protected]");

			student.setName("张小三");

			student.setNickName("张三");

			student.setPhone("15159665635");

			student.setQq("599194993");

			student.setRemark("但是房间啊看的舒服噶说的法规大家看沙发党就看啥好烦开朗大方黄寺大街咖啡还是大家看法还是大家看法好");

			session.save(student);

			transaction.commit();

		}

		session.flush();

	}

	

	

	

}






 

 

你可能感兴趣的:(Hibernate)