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>