数据库连接池配置

数据库连接池(二)

  • 数据库连接池配置
  1. druid配置

Jar包:druid-1.0.9.jar  

<context:property-placeholder location="classpath:db.properties"/>      

    <bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource" init-method="init" destroy-method="close">

       

        <property name="driverClassName" value="${jdbc.driverClass}" />

        <property name="url" value="${jdbc.jdbcUrl}" />

        <property name="username" value="${jdbc.user}" />

        <property name="password" value="${jdbc.password}" />

           

       

        <property name="initialSize" value="5" />

        <property name="minIdle" value="3" />

        <property name="maxActive" value="300" />

         

       

        <property name="maxWait" value="10000" />

       

        <property name="timeBetweenEvictionRunsMillis" value="60000" />

       

        <property name="minEvictableIdleTimeMillis" value="300000" />

           

         

        <property name="validationQuery" value="SELECT 1 FROM DUAL" /> 

        <property name="testWhileIdle" value="true" /> 

        <property name="testOnBorrow" value="false" /> 

        <property name="testOnReturn" value="false" /> 

           

         

        <property name="poolPreparedStatements" value="true" /> 

        <property name="maxPoolPreparedStatementPerConnectionSize" value="20" /> 

      

         

        <property name="filters" value="stat,wall,log4j" /> 

             

       

        

           

         

        <property name="proxyFilters"> 

            <list> 

                <ref bean="stat-filter" /> 

                <ref bean="log-filter" /> 

            list> 

        property> 

bean>

 

     

    <bean id="stat-filter" class="com.alibaba.druid.filter.stat.StatFilter"> 

        <property name="mergeSql" value="true" /> 

        <property name="slowSqlMillis" value="10000" /> 

        <property name="logSlowSql" value="true" /> 

    bean> 

          

    <bean id="log-filter" class="com.alibaba.druid.filter.logging.Log4jFilter"> 

         

         

bean>

 

监控访问地址:XXX/项目名称/druid/index.html

例如:localhost:8080/fss/druid/index.html

 

  1. C3P0配置

Jar包:c3p0-0.9.1.2.jar 、 mchange-commons-java-0.2.3.4.jar

           

           

           

           

            初始化数据库连接池时连接的数量

           

            数据库连接池中的最大的数据库连接数

           

            数据库连接池中的最小的数据库连接数

           

 

3.DBCP配置

Jar包:commons-dbcp.jar,commons-pool.jar

    <bean id="propertyConfigurer"

    class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">

        <property name="location" value="classpath:jdbc.properties" />

    bean>

   

   

    <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">

        <property name="driverClassName" value="${driver}">property>

        <property name="url" value="${url}">property>

        <property name="username" value="${username}">property>

        <property name="password" value="${password}">property>

 

   

bean>

 

  1. Proxool配置

 Jar包:proxool-0.9.1.jar proxool-cglib.jar

<bean id="dataSource" class="org.logicalcobwebs.proxool.ProxoolDataSource">

        <property name="driver"><value>oracle.jdbc.driver.OracleDrivervalue>property>

        <property name="driverUrl"><value>jdbc:oracle:thin:@10.246.109.35:1521:orclvalue>property>

        <property name="user"><value>CMS_SC35value>property>

        <property name="password"><value>CMS_SC35value>property>

 

        <property name="alias" value="sspDs" />

        <property name="prototypeCount" value="0" />

        <property name="minimumConnectionCount" value="1" />

        <property name="maximumConnectionCount" value="50" />

        <property name="simultaneousBuildThrottle" value="50" />

        <property name="houseKeepingSleepTime" value="90000" />

        <property name="houseKeepingTestSql" value="select CURRENT_DATE from dual" />

 

        <property name="maximumActiveTime"         value="172800000" />

        <property name="maximumConnectionLifetime" value="180000000" />

        <property name="testBeforeUse" value="true" />

        <property name="testAfterUse"  value="true" />

bean>

你可能感兴趣的:(数据源专题)