日期:2014-05-19 浏览次数:20738 次
SessionFactory sf = hibernateTemplate.getSessionFactory(); //session不是从事务中获取的、自己新创个、 Session session = sf.openSession(); session.getTransaction().begin(); long s = System.currentTimeMillis(); //循环保存、累积一起提交事务 time++ session.getTransaction().commit(); long e = System.currentTimeMillis(); System.out.println("共执行了"+time+"行数据用时:"+(e-s)+"ms"); session.flush(); session.clear(); session.close();
<bean id="hibernateTemplate" class="org.springframework.orm.hibernate3.HibernateTemplate"> <property name="sessionFactory" ref="sessionFactory"/> <property name="cacheQueries" value="true"/> <property name="fetchSize" value="100"/> <property name="maxResults" value="10000"/> </bean> <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close"> <property name="driverClass"> <value>${c3p0.driverClass}</value> </property> <property name="jdbcUrl"> <value>${c3p0.jdbcUrl}</value> </property> <property name="user"> <value>${c3p0.user}</value> </property> <property name="password"> <value>${c3p0.password}</value> </property> <property name="minPoolSize"> <value>5</value> </property> <property name="maxPoolSize"> <value>50</value> </property> <property name="initialPoolSize"> <value>5</value> </property> <property name="maxIdleTime"> <value>10</value> </property> <!--最大连接数后一次取多少--> <property name="acquireIncrement"> <value>5</value> </property> <property name="acquireRetryAttempts"> <value>30</value> </property> <property name="acquireRetryDelay"> <value>1000</value> </property> <property name="testConnectionOnCheckin"> <value>true</value> </property> <property name="automaticTestTable"> <value>conn_test</value> </property> <property name="idleConnectionTestPeriod"> <value>60</value> </property> <property name="checkoutTimeout"> <value>100</value> </property> <property name="numHelperThreads">