C3P0 (com.mchange.v2.c3p0.ComboPooledDataSource) の詳細設定手順
2022-02-26 06:54:08
C3P0 is an open source JDBC connection pool that is distributed with Hibernate in the lib directory and includes DataSources objects that implement the Connection and Statement pools described in the jdbc3 and jdbc2 extension specifications.
c3p0-config>
<default-config>
<! -- The number of connections c3p0 will fetch 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 table for the test must exist at the time of the initial data source. default: null -->
<property name="preferredTestQuery">select id from test where id=1</property>
<! --User waits up to 300 seconds before modifying system configuration parameters to execute.Default: 300 -->
<property name="propertyCycle">300</property>
<! -- please use it only when needed due to high performance consumption. If set to true then each connection commit will be checked for validity at the time of
will be checked for validity at each connection commit. 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>
<! -- Validate the connection every time
関連
-
[解決済み] Hibernateはorg.hibernate.AnnotationExceptionをスローします。エンティティに指定された識別子がありません: com..domain.idea.MAE_MFEView
-
[解決済み】Hibernateの問題 - "マッピングされていないクラスをターゲットにした@OneToManyまたは@ManyToManyの使用"
-
[解決済み】DTOからエンティティへ、エンティティからDTOへ
-
[解決済み] org.hibernate.PersistentObjectException: 永続化するために渡されたデタッチド・エンティティー
-
[解決済み] Another エンティティのマッピングでカラムが繰り返されるエラー
-
[解決済み] Hibernate関数Restrictions.allEq(Map<String、Object>)は、どのようにNULL値を処理しますか?
-
PersistentObjectException: 永続化例外に渡された離脱したエンティティ
-
問題解決:ロール例外のコレクションを遅延して初期化することに失敗しました。
-
com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException 解決法
-
トランザクションのためにHibernateセッションを開くことができず、データベース接続タイムアウトの解決法
最新
-
nginxです。[emerg] 0.0.0.0:80 への bind() に失敗しました (98: アドレスは既に使用中です)
-
htmlページでギリシャ文字を使うには
-
ピュアhtml+cssでの要素読み込み効果
-
純粋なhtml + cssで五輪を実現するサンプルコード
-
ナビゲーションバー・ドロップダウンメニューのHTML+CSSサンプルコード
-
タイピング効果を実現するピュアhtml+css
-
htmlの選択ボックスのプレースホルダー作成に関する質問
-
html css3 伸縮しない 画像表示効果
-
トップナビゲーションバーメニュー作成用HTML+CSS
-
html+css 実装 サイバーパンク風ボタン
おすすめ
-
[解決済み] ConfigurationException: プロジェクトのルート・フォルダに cfg.xml リソース [hibernate.cfg.xml] が見つかりませんでした。
-
[解決済み] Spring Boot spring.datasource.schema VS spring.jpa.properties.hibernate.default_schema
-
[解決済み] Spring HibernateのDataIntegrityViolationExceptionを解決するにはどうすればよいですか?
-
Hibernate Newbie FAQ org.hibernate.service.spi.ServiceException: 要求されたサービスを作成できません
-
エラー バッチアップデートが予期しない行数を返しました。
-
[解決済み] Spring MVC + Hibernate: ロードするためのidが必要
-
[解決済み] not-nullプロパティは、NULL値または一時的な値を参照します。