Connection pool learning

1. Common types of open source connection pools

dbcp

<!-- datasource1 -->
    <bean id="dataSource"
          class="org.apache.commons.dbcp.BasicDataSource"
          destroy-method="close">
        <property name="driverClassName" value="com.mysql.jdbc.Driver"/>
        <property name="url" value="jdbc:mysql://192.168.0.109:3306/test?useUnicode=true&characterEncoding=UTF-8"/>
        <property name="username" value="root"/>
        <property name="password" value="root"/>
        <!--maxActive: maximum number of connections -->  
        <property name="maxActive" value="150"/>
        <!--minIdle: Minimum idle connection -->  
        <property name="minIdle" value="5"/>
        <!--maxIdle: maximum idle connections -->  
        <property name="maxIdle" value="20"/>
        <!--initialSize: initialize connection -->  
        <property name="initialSize" value="30"/>
        <!-- Whether to print when the connection is leaked -->
        <property name="logAbandoned" value="true"/>
        <!--removeAbandoned: Whether to automatically recycle timeout connections -->  
        <property name="removeAbandoned"  value="true"/>
        <!--removeAbandonedTimeout: timeout (in seconds) -->  
        <property name="removeAbandonedTimeout" value="10"/>
        <!--maxWait: timeout waiting time in milliseconds 1000 equals 60 seconds -->
        <property name="maxWait" value="1000"/>
        <!-- The amount of time in milliseconds to sleep while the idle connection collector thread is running. -->
        <property name="timeBetweenEvictionRunsMillis" value="10000"/>
        <!-- The number of connections to check each time the idle connection collector thread (if any) runs -->
        <property name="numTestsPerEvictionRun" value="10"/>
        <!-- 1000 * 60 * 30 connections remain idle in the pool without being idled by the connection collector thread -->
        <property name="minEvictableIdleTimeMillis" value="10000"/>
	<property name="validationQuery" value="SELECT NOW() FROM DUAL"/>
    </bean>


Reference article: https://blog.csdn.net/fairyhawk/article/details/7565391

Official description: http://commons.apache.org/proper/commons-dbcp/configuration.html


c3p0

<!-- c3p0 connection pool configuration-->
     <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
          <!-- username-->
          <property name="user" value="${username}"/>
          <!-- user password-->
          <property name="password" value="${password}"/>
          <property name="driverClass" value="${driver_class}"/>
          <property name="jdbcUrl" value="${url}"/>

           <!--The maximum number of connections to keep in the connection pool. Default: 15 -->
          <property name="maxPoolSize" value="20"/>
          <!-- The minimum number of connections reserved in the connection pool, the default is: 3-->
          <property name="minPoolSize" value="2"/>
          <!-- Initialize the number of connections in the connection pool, the value should be between minPoolSize and maxPoolSize, the default is 3-->
          <property name="initialPoolSize" value="2"/>

          <!--Maximum idle time, the connection is dropped if it is not used within 60 seconds. If it is 0, it will never be discarded. Default: 0 -->
          <property name="maxIdleTime">60</property>
          
          <!-- When the connection pool connection is exhausted, the client waits for a new connection after calling getConnection(). After the timeout, an SQLException will be thrown. If it is set to 0, it will wait indefinitely. The unit is milliseconds. Default: 0 -->
          <property name="checkoutTimeout" value="3000"/>
          
          <!--The number of connections obtained by c3p0 at one time when the connections in the connection pool are exhausted. Default: 3 -->
          <property name="acquireIncrement" value="2"/>

         <!--Defines the number of repeated attempts after getting a new connection from the database fails. Default value: 30 ; less than or equal to 0 means infinite -->
          <property name="acquireRetryAttempts" value="0"/>

          <!--Retry interval, default: 1000ms-->
          <property name="acquireRetryDelay" value="1000" />

          <!--When closing the connection, whether to commit the uncommitted transaction, the default is false, that is, close the connection and roll back the uncommitted transaction-->
          <property name="autoCommitOnClose">false</property>

          <!--c3p0 will create an empty table named Test and use its own query statement for testing. If this parameter is defined then the attribute preferredTestQuery will be ignored. You cannot do anything on this Test sheet, it will only be used by c3p0 tests. Default: null -->
          <property name="automaticTestTable">Test</property>

          <!--If it is false, the failure to obtain the connection will cause all threads waiting for the connection pool to obtain the connection to throw an exception, but the data source is still valid and will continue to try to obtain the connection the next time getConnection() is called. If set to true, the data source will be declared disconnected and permanently closed after a failed connection attempt. Default: false-->
          <property name="breakAfterAcquireFailure">false</property>

          <!--Check all connection pools for idle connections every 60 seconds. Default: 0, do not check -->
          <property name="idleConnectionTestPeriod">60</property>
          <!--c3p0 The size of the global PreparedStatements cache. If both maxStatements and maxStatementsPerConnection are 0, the cache will not take effect. As long as one of them is not 0, the statement cache will take effect. If default value: 0-->
          <property name="maxStatements">100</property>
          <!--maxStatementsPerConnection defines the maximum number of cached statements owned by a single connection in the connection pool. Default: 0 -->
          <property name="maxStatementsPerConnection"></property>
     </bean>


Reference article: https://blog.csdn.net/caihaijiang/article/details/6843496

Official description: http://www.mchange.com/projects/c3p0/index.html


proxool

jdbc-0.proxool.alias=test
jdbc-0.proxool.driver-class=org.postgresql.Driver
jdbc-0.proxool.driver-url=jdbc:postgresql://localhost/portal
jdbc-0.user=postgres
jdbc-0.password=password
(Add other attributes by yourself)
jdbc-0.proxool.maximum-connection-count=10
jdbc-0.proxool.prototype-count=4
jdbc-0.proxool.house-keeping-test-sql=SELECT CURRENT_DATE
jdbc-0.proxool.verbose=true
jdbc-0.proxool.statistics=10s,1m,1d
jdbc-0.proxool.statistics-log-level=DEBUG
jdbc-0.proxool.house-keeping-sleep-time=30000
jdbc-0.proxool.maximum-connection-lifetime=60000
jdbc-0.proxool.simultaneous-build-throttle=1
jdbc-0.proxool.overload-without-refusal-lifetime=10000
jdbc-0.proxool.maximum-active-time=50000
jdbc-0.proxool.trace=true
jdbc-0.proxool.fatal-sql-exception=ORA-1234
jdbc-0.proxool.prototype-count=2

just put

<param-name>xmlFile</param-name>

<param-value>WEB-INF/classes/proxool.xml</param-value>  

Change it to:

<param-name>propertyFile</param-name>

<param-value>WEB-INF/Proxool.properties</param-value>


Reference article: https://blog.csdn.net/lv_shijun/article/details/77679268




Reference article: https://blog.csdn.net/m0_37893932/article/details/73930014

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324618476&siteId=291194637