标签:style blog color os 使用 io for ar 数据
关于c3p0、dbcp和proxool,之类的比较,配置在网上有很多的文章,我这边就不浪费大家的时间了,主要讲下我用过这三个之后的体会。
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource"> <property name="driverClassName" value="org.logicalcobwebs.proxool.ProxoolDriver" /> <property name="url" value="xxxx.xml" /> </bean> 在xxxx.xml里配置
<proxool> <alias>pool</alias> <driver-url>jdbc:mysql://192.168.1.4:3306/MIGRATE_TEST?characterEncoding=utf- 8&autoReconnect=true</driver-url> <driver-class>com.mysql.jdbc.Driver</driver-class> <driver-properties> <property name="user" value="website" /> <property name="password" value="website" /> <property name="autoReconnect" value="true" /> </driver-properties> <minimum-connection-count>1</minimum-connection-count> <maximum-connection-count>8</maximum-connection-count> <prototype-count>1</prototype-count> <test-before-use>true</test-before-use> <house-keeping-sleep-time>60000</house-keeping-sleep-time> </proxool>
mysql的URL的后面要加上autoReconnect=true,值得注意的是,当使用ibatis时,日志会报warn:registered a statement as closed which wasn‘t known to be open. 那是因为在ibatis package org.springframework.orm.ibatis; public class SqlMapClientTemplate extends JdbcAccessor implements SqlMapClientOperations { public <T> T execute(SqlMapClientCallback<T> action) throws DataAccessException { .......... finally { // Only close SqlMapSession if we know we‘ve actually opened it // at the present level. if (ibatisCon == null) { session.close();// 由这段引起的,池ibatisCon不为空时,session永远不会关闭 } } } }
if (ibatisCon != null),就行了
4. 根据以上三种连接池的情况来看,在首次访问时,dbcp大约需要600毫秒,c3p0需要450毫秒,proxool需要1356毫秒,访问后,速度基本都在几十毫秒以内,除非sql写得很复杂。
标签:style blog color os 使用 io for ar 数据
原文地址:http://www.cnblogs.com/estellez/p/3939877.html