tomcat jdbcpoolsql
<bean id="dataSource" class="org.apache.tomcat.jdbc.pool.DataSource" destroy-method="close">
<property name="poolProperties">
<bean class="org.apache.tomcat.jdbc.pool.PoolProperties">
<property name="url" value="${jdbc.url}"/>
<property name="driverClassName" value="${jdbc.driver}"/>
<property name="username" value="${jdbc.username}"/>
<property name="password" value="${jdbc.password}"/>
<property name="jmxEnabled" value="true"/>
<property name="testWhileIdle" value="false"/>
<property name="testOnBorrow" value="true"/>
<property name="validationInterval" value="30000"/>
<property name="testOnReturn" value="false"/>
<property name="validationQuery" value="select 1"/>
<property name="timeBetweenEvictionRunsMillis" value="30000"/>
<property name="maxActive" value="50"/>
<property name="initialSize" value="20"/>
<property name="maxWait" value="10000"/>
<property name="removeAbandonedTimeout" value="60"/>
<property name="minEvictableIdleTimeMillis" value="30000"/>
<property name="minIdle" value="10"/>
<property name="logAbandoned" value="true"/>
<property name="removeAbandoned" value="true"/>
<property name="jdbcInterceptors" value="org.apache.tomcat.jdbc.pool.interceptor.ConnectionState;org.apache.tomcat.jdbc.pool.interceptor.StatementFinalizer"/>
</bean>
</property>
</bean> 数据库
dbcp2apache
<bean id="dataSource" class="org.apache.commons.dbcp2.BasicDataSource">
<!-- 数据库基本信息配置 -->
<property name="url" value="${jdbc.url}" />
<property name="driverClassName" value="${jdbc.driver}" />
<property name="username" value="${jdbc.username}" />
<property name="password" value="${jdbc.password}" />tomcat
<property name="maxIdle" value="${dbcp2.maxIdle}" />
<property name="minIdle" value="${dbcp2.minIdle}" />
<property name="initialSize" value="${dbcp2.initialSize}" />
<property name="timeBetweenEvictionRunsMillis" value="${dbcp2.timeBetweenEvictionRunsMillis}" />安全
<property name="poolPreparedStatements" value="${dbcp2.poolPreparedStatements}" />
<property name="maxOpenPreparedStatements" value="${dbcp2.maxOpenPreparedStatements}" />
<property name="removeAbandonedTimeout" value="${dbcp2.removeAbandonedTimeout}" />性能
<!-- 申请链接时执行validationQuery检测链接是否有效,配置为true会下降性能 -->
<property name="testOnBorrow" value="${dbcp2.testOnBorrow}" />ui
<!-- 归还链接时执行validationQuery检测链接是否有效,配置为true会下降性能 -->
<property name="testOnReturn" value="${dbcp2.testOnReturn}" />url
<!-- 建议配置为true,不影响性能,而且保证安全性。申请链接的时候检测,若是空闲时间大于 timeBetweenEvictionRunsMillis,执行validationQuery检测链接是否有效。 -->
<property name="testWhileIdle" value="${dbcp2.testWhileIdle}" />rem
<!-- 用来检测链接是否有效的sql,要求是一个查询语句,若是validationQuery为 null,testOnBorrow、testOnReturn、testWhileIdle都不起其做用。 -->
<property name="validationQuery" value="${dbcp2.validationQuery}" />
</bean>it
druid
<bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource" init-method="init" destroy-method="close">
<!-- 基本属性 url、user、password -->
<property name="url" value="${jdbc.url}" />
<property name="username" value="${jdbc.username}" />
<property name="password" value="${jdbc.password}" />
<!-- 配置初始化大小、最小、最大 -->
<property name="initialSize" value="20" />
<property name="minIdle" value="10" />
<property name="maxActive" value="50" />
<!-- 配置获取链接等待超时的时间 -->
<property name="maxWait" value="60000" />
<!-- 配置间隔多久才进行一次检测,检测须要关闭的空闲链接,单位是毫秒 -->
<property name="timeBetweenEvictionRunsMillis" value="60000" />
<!-- 配置一个链接在池中最小生存的时间,单位是毫秒 -->
<property name="minEvictableIdleTimeMillis" value="300000" />
<property name="validationQuery" value="SELECT 'x' FROM DUAL" />
<property name="testWhileIdle" value="true" />
<property name="testOnBorrow" value="false" />
<property name="testOnReturn" value="false" />
<!-- 打开PSCache,而且指定每一个链接上PSCache的大小 -->
<property name="poolPreparedStatements" value="true" />
<property name="maxPoolPreparedStatementPerConnectionSize" value="20" />
<!-- 配置监控统计拦截的filters,去掉后监控界面sql没法统计 -->
<property name="filters" value="stat" />
</bean>
c3p0
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close">
<property name="driverClass" value="${jdbc.driver}" />
<property name="jdbcUrl" value="${jdbc.url}" />
<property name="user" value="${jdbc.username}" />
<property name="password" value="${jdbc.password}" />
<property name="minPoolSize" value="10" />
<property name="maxPoolSize" value="50" />
<property name="initialPoolSize" value="20" />
<property name="maxIdleTime" value="25000" />
<property name="acquireIncrement" value="1" />
<property name="acquireRetryAttempts" value="30" /> <property name="acquireRetryDelay" value="1000" /> <property name="testConnectionOnCheckin" value="true" /> <property name="idleConnectionTestPeriod" value="18000" /> <property name="checkoutTimeout" value="3000" /> </bean>