1. ホーム
  2. Java

Spring c3p0 接続プール構成 com.mchange.v2.c3p0.combopooleddatasource

2022-02-26 01:40:08
<default-config>  


  <! -- The number of connections c3p0 will acquire at once when the connection pool runs out of connections. default: 3 -->  
  <property name="acquireIncrement">3</property>  


  <! -- Defines the number of repeated attempts after a failed attempt to get a new connection from the database. default: 30 -->  
  <property name="acquireRetryAttempts">30</property>  


  <! -- Time between connections, in milliseconds. default: 1000 -->  
  <property name="acquireRetryDelay">1000</property>  


  <! -- Rollback all uncommitted operations by default when the connection is closed. default: false -->  
  <property name="autoCommitOnClose">false</property>  


  <! --c3p0 will create an empty table named Test and test it with its own query statement. If this parameter is defined then the  
  propertypreferredTestQuery will be ignored. You cannot perform any operations on this Test table, it will only be used by c3p0 for testing.  
  Default: null -->  


  <property name="automaticTestTable">Test</property>  
  <! -- Failing to get a connection will cause all threads waiting for the connection pool to get a connection to throw an exception. But the data source is still valid  
  is retained and the next call to getConnection() will continue to try to get the connection. If set to true, then the data source will be retained after a failed attempt to  
  Default: false -->  
  <property name="breakAfterAcquireFailure">false</property>  


  <! -- When the connection pool is exhausted, the client calls getConnection() and waits for the time to get a new connection, after the timeout will throw  
  SQLException, if set to 0, then wait indefinitely. Default: 0 -->  
  <property name="checkoutTimeout">100</property>                                                                                           
  <! -- Test the connection by means of a class that implements ConnectionTester or QueryConnectionTester. The full path needs to be developed for the class name.  
  Default: com.mchange.v2.c3p0.impl.DefaultConnectionTester -->  
  <property name="connectionTesterClassName"></property>  


  <! -- Specify the path to the c3p0 libraries, if (as is often the case) they are available locally then there is no need to set them, the default is null  
  Default: null -->  
  <property name="factoryClassLocation">null</property>  


  <! --Setting this to true may lead to subtle and bizarre bugs.  
  (Original document) One property that the authors strongly recommend not using -->  


  <property name="forceIgnoreUnresolvedTransactions">false</property>  
  <! --check all idle connections in the connection pool every 60 seconds.Default: 0 -->  


  <property name="idleConnectionTestPeriod">60</property>  
  <! --Initialize to get three connections, the value should be between minPoolSize and maxPoolSize. default: 3 -->  


  <property name="initialPoolSize">3</property>  
  <! --Maximum idle time, if not used within 60 seconds, the connection is dropped. Default: 0 -->  


  <property name="maxIdleTime">60</property>  
  <! --max number of connections to keep in the connection pool. default: 15 -->  


  <property name="maxPoolSize">15</property>  
  <! -- A standard JDBC parameter to control the number of PreparedStatements loaded within the data source. However, since the pre-cached statements  
  belong to a single connection and not to the entire connection pool. So setting this parameter takes into account various factors.  
  If both maxStatements and maxStatementsPerConnection are 0, the cache is turned off. default: 0 -->  
  <property name="maxStatements">100</property>  


  <! --maxStatementsPerConnection defines the maximum number of cached statements a single connection can have within the connection pool.Default: 0 -->  
  <property name="maxStatementsPerConnection"></property>  


  <! --c3p0 is operated asynchronously and slow JDBC operations are done through helper processes. Extending these operations can effectively improve performance  
  Default: 3 -->  
  <property name="numHelperThreads">3</property>  


  <! -- Makes the root user the user who goes to get the connection when the user calls getConnection(). This is mainly used when connection pools connect to non-c3p0 data sources.  
  Default: null -->  
  <property name="overrideDefaultUser">root</property>  


  <! --one parameter used in correspondence with the overrideDefaultUser parameter. default: null -->  
  <property name="overrideDefaultPassword">password</property>  


  <! --password. default: null -->  
  <property name="password"></property>  


  <! -- Defines the test statements that are executed by all connection tests. This one significantly improves the speed of testing in the case of using connection tests. Caution.  
  The test of
  The validity of the test will be verified when the test is run. It is recommended to use methods such as idleConnectionTestPeriod or automaticTestTable  
  Default: false -->  
  <property name="testConnectionOnCheckout">false</property>  


  <! --Default: false -->  
  <property name="testConnectionOnCheckin">true</property>  
  <! --username. default: null -->  


  <property name="user">root</property>  
  Configuration in Hibernate (spring admin).  


  <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close">  
  <property name="driverClass"><value>oracle.jdbc.driver.OracleDriver</value></property>  
  <property name="jdbcUrl"><value>jdbc:oracle:thin: @localhost :1521:Test</value></property>  
  <property name="user"><value>Kay</value></property>  
  <property name="password"><value>root</value></property>  


  <! -- The minimum number of connections to keep in the connection pool. -->  
  <property name="minPoolSize" value="10" />  


  <! -- The maximum number of connections to keep in the connection pool. default: 15 -->  
  <property name="maxPoolSize" value="100" />  


  <! --Maximum idle time, if not used within 1800 seconds then the connection is dropped. Default: 0 -->  
  <property name="maxIdleTime" value="1800" />  


  <! -- The number of connections c3p0 will fetch at once when the connection pool runs out of connections. default: 3 -->  
  <property name="acquireIncrement" value="3" />  
  <property name="maxStatements" value="1000" />  
  <property name="initialPoolSize" value="10" />  


  <! -- Check all idle connections in the connection pool every 60 seconds. default: 0 -->  
  <property name="idleConnectionTestPeriod" value="60" />  


  <! -- Defines the number of repeated attempts after a failed attempt to get a new connection from the database. default: 30 -->  
  <property name="acquireRetryAttempts" value="30" />  


  <property name="breakAfterAcquireFailure" value="true" />  
  <property name="testConnectionOnCheckout" value="false" />  


  </bean> 


  ########################### 


  ### C3P0 Connection Pool### 


  ########################### 


  ### hibernate.c3p0.max_size 2 


  ## hibernate.c3p0.min_size 2 


  #hibernate.c3p0.timeout 5000 


  #hibernate.c3p0.max_statements 100 


  #hibernate.c3p0.idle_test_period 3000 


  #hibernate.c3p0.acquire_increment 2 


  #hibernate.c3p0.validate false 


  Add the following configuration to the hibernate.cfg.xml file. 


  <! --max-join-count --> 
  <property name="hibernate.c3p0.max_size">20</property> 


  <! -- Minimum number of connections --> 
  <property name="hibernate.c3p0.min_size">5</property> 


  <! -- Get the timeout of the connection, if it exceeds this time, an exception will be thrown in milliseconds --> 
  <property name="hibernate.c3p0.timeout">120</property> 


  <! -- the maximum number of PreparedStatements -- > 
  <property name="hibernate.c3p0.max_statements">100</property> 


  <! -- Check for free connections in the connection pool every 120 seconds, in seconds -- > 
  <property name="hibernate.c3p0.idle_test_period">120</property> 


  <! -- The number of new connections C3P0 gets at once when the connections inside the connection pool run out -- > 
  <property name="hibernate.c3p0.acquire_increment">2</property> 


  <! -- verify that the connection is available every time --> 
  <property name="hibernate.c3p0.validate">true</property>