The online evaluation of three connection pools is as follows:
C3P0 is more resource-consuming and may be a little lower in terms of efficiency.
There are bugs in DBCP in practice, and in some cases, many empty connections cannot be released. Hibernate 3.0 has given up its support.
Proxool has fewer negative reviews and is recommended now, and it also provides instant monitoring of connection pool status to facilitate connection leakage.
Proxool connection pool
<bean id="proxool_dataSource"> <property name="driver-class" value="oracle.jdbc.driver.OracleDriver"/> <property name="driver-url" value="jdbc:oracle:thin:@localhost:1521/ssid"/> <property name="user" value="user"/> <property name="password" value="password"/> <!-- SQL execution statement for test --> <property name="houseKeepingTestSql" value="select CURRENT_DATE"/> <!-- The minimum number of idle connections maintained (default 2) --> <property name="prototypeCount" value="2"/> <!-- proxool automatically detects the time interval (milliseconds) of each connection state. If the idle connection is detected, it will be recycled immediately. The timeout destruction defaults to 30 seconds) --> <property name="houseKeepingSleepTime" value="30"/> <!-- Maximum activity time (threads exceeding this time will be killed, default is 5 minutes) --> <property name="maximumActiveTime" value="300"/> <!-- Maximum connection time (default 4 hours) --> <property name="maximumConnectionLifetime" value="30"/> <!-- Minimum number of connections (default 2) --> <property name="minimumConnectionCount" value="10"/> <!-- Maximum number of connections (default 5) --> <property name="maximumConnectionCount" value="30"/> <!-- Maximum number of connections at the same time--> <property name="simultaneousBuildThrottle" value="10"/></bean>
C3P0 connection pool
<beanid="dataSource"class="com.mchange.v2.c3p0.ComboPooledDataSource"destroy-method="close"> <propertyname="driverClass"value="oracle.jdbc.driver.OracleDriver"/> <propertyname="jdbcUrl"value="jdbc:oracle:thin:@localhost:1521/ssid"/> <propertyname="user"value="user"/> <propertyname="password"value="password"/> <propertyname="initialPoolSize"value="10"/> <propertyname="minPoolSize"value="10"/> <propertyname="maxPoolSize"value="100"/></bean> <!-- C3P0's configuration properties, through these properties, various effective controls can be performed on the data source: acquireIncrement: When the connection in the connection pool is used up, C3P0 creates new connections at one time; acquireRetryAttempts: Define the number of repeated attempts to obtain after the failure to obtain a new connection from the database, the default is 30; acquireRetryDelay: The interval between two connections, unit milliseconds, the default is 1000; autoCommitOnClose: When the connection is closed, all uncommitted operations are rolled back by default. Default is false; automaticTestTable: C3P0 will create an empty table named Test and use its own query statement for testing. If this parameter is defined, the property preferredTestQuery will be ignored. You cannot do anything on this Test table, it will be used for C3P0 tests, default to null; breakAfterAcquireFailure: Failure to get the connection will cause all threads waiting to get the connection to throw exceptions. However, the data source is still valid and continues to try to get the connection the next time you call getConnection(). If set to true, the data source will declare that it has been disconnected and permanently closed after failed attempts to obtain the connection. Default is false; checkoutTimeout: When the connection pool is used up, the client calls getConnection() and waits for the time to get the new connection. After the timeout, SQLException will be thrown. If set to 0, it will wait indefinitely. Unit milliseconds, default is 0; connectionTesterClassName: Test connections by implementing ConnectionTester or QueryConnectionTester, the class name must be set to a fully qualified name. The default is com.mchange.v2.C3P0.impl.DefaultConnectionTester; idleConnectionTestPeriod: How many seconds does it take to check the idle connections in all connection pools, the default is 0 to indicate that it is not checked; initialPoolSize: The number of connections created during initialization should be valued between minPoolSize and maxPoolSize. The default is 3; maxIdleTime: maximum idle time, connections that exceed idle time will be discarded. If it is 0 or negative, it will never be discarded. Default is 0; maxPoolSize: The maximum number of connections retained in the connection pool. The default is 15; maxStatements: The standard parameter of JDBC, used to control the number of PreparedStatements loaded in the data source. But because the precache Statement belongs to a single Connection rather than the entire connection pool. Therefore, setting this parameter requires considering many factors. If both maxStatements and maxStatementsPerConnection are 0, the cache will be closed. Default is 0; maxStatementsPerConnection: The maximum number of cached Statements that a single connection in the connection pool has. Default is 0; numHelperThreads: C3P0 is asynchronously operated, and slow JDBC operations are completed through the help process. Extending these operations can effectively improve performance and multiple operations are executed simultaneously through multiple threads. Default is 3; preferredTestQuery: Defines the test statement that all connection tests are executed. This parameter can significantly improve the test speed when using connection tests. The tested table must exist at the time of the initial data source. Default is null; propertyCycle: The maximum number of seconds to wait before the user modifys the system configuration parameters. The default is 300; testConnectionOnCheckout: Please only use it when needed due to high performance consumption. If set to true, its validity will be verified at each connection submission. It is recommended to use idleConnectionTestPeriod or automaticTestTable to improve the performance of connection testing. Default is false; testConnectionOnCheckin: If set to true, the validity of the connection will be checked while obtaining the connection. Default is false. -->
DBCP connection pool
<beanid="dbcp_dataSource"class="org.apache.commons.dbcp.BasicDataSource"> <propertyname="driverClassName"value="oracle.jdbc.driver.OracleDriver"></property> <propertyname="url"value="jdbc:oracle:thin:@localhost:1521/ssid"></property> <propertyname="username"value="user"></property> <propertyname="password"value="password"></property> <propertyname="initialSize"value="3"></property> <propertyname="maxActive"value="50"></property> <propertyname="maxActive"value="50"></property> <propertyname="maxIdle"value="20"></property> <propertyname="minIdle"value="5"></property> <propertyname="maxWait"value="10"></property> </bean> <!-- DBCP data source attribute description initialSize: initial number of connections when initializing connection pool maxActive: maximum value of connection pool maxIdle: maximum idle value minIdle: minimum idle value maxWait: maximum connection establishment waiting time -->