2017-05-17 37 views
1

私はアプリケーションでDAOを管理するためにHibernateとc3p0を使用しています。Hibernate/c3p0:接続プールがいっぱいです:「プールはすでに最大値に達しています」エラー

しばらくすると問題があります。アプリケーション、より正確にはBDDリクエストは機能しません。理由:接続プールがいっぱいです。

私は次のメッセージを持っている:

com.mchange.v2.resourcepool.BasicResourcePool - acquire test -- pool is already maxed out. [managed: 20; max: 20] 
[email protected] [managed: 20, unused: 0, excluded: 0] (e.g. [email protected]) 

接続が閉じられることはありませんしているようだ、それが最大値に達するまで、ログファイルに私たちが見る、20(接続プールが各要求で満たされていることがわかります上記のエラー):

hibernate.connection.release_mode=on_close 
hibernate.c3p0.validate=true 
hibernate.c3p0.min_size=5 
hibernate.c3p0.max_size=20 
hibernate.c3p0.timeout=1800 
hibernate.c3p0.max_statements=50 
hibernate.c3p0.preferredTestQuery=SELECT 1; 
hibernate.c3p0.idle_test_period=3000 
hibernate.c3p0.acquire_increment=1 
:私はC3P0ため、以下の構成を設定している

[2017/05/11 10:06:48] [http-bio-0.0.0.0-20443-exec-4] DEBUG (LogicalConnectionImpl.java:226) org.hibernate.engine.jdbc.internal.LogicalConnectionImpl - Obtaining JDBC connection 
[2017/05/11 10:06:48] [http-bio-0.0.0.0-20443-exec-4] DEBUG (BasicResourcePool.java:587) com.mchange.v2.resourcepool.BasicResourcePool - acquire test -- pool size: 16; target_pool_size: 16; desired target? 17 
[2017/05/11 10:06:48] [http-bio-0.0.0.0-20443-exec-4] DEBUG (BasicResourcePool.java:450) com.mchange.v2.resourcepool.BasicResourcePool - incremented pending_acquires: 1 
[2017/05/11 10:06:48] [http-bio-0.0.0.0-20443-exec-4] DEBUG (BasicResourcePool.java:1788) com.mchange.v2.resourcepool.BasicResourcePool - Starting acquisition series. Incremented pending_acquires [1], attempts_remaining: 30 
[2017/05/11 10:06:48] [http-bio-0.0.0.0-20443-exec-4] DEBUG (ThreadPoolAsynchronousRunner.java:236) com.mchange.v2.async.ThreadPoolAsynchronousRunner - [email protected]: Adding task to queue -- com[email protected]232613e3 
[2017/05/11 10:06:48] [http-bio-0.0.0.0-20443-exec-4] DEBUG (BasicResourcePool.java:1390) com.mchange.v2.resourcepool.BasicResourcePool - awaitAvailable(): [email protected] 
[2017/05/11 10:06:48] [http-bio-0.0.0.0-20443-exec-4] DEBUG (BasicResourcePool.java:1747) com.mchange.v2.resourcepool.BasicResourcePool - trace [email protected] [managed: 16, unused: 0, excluded: 0] (e.g. [email protected]) 
[2017/05/11 10:06:48] [C3P0PooledConnectionPoolManager[identityToken->2v3o059n1wfndya61hxar|3b29a008]-HelperThread-#1] DEBUG (GooGooStatementCache.java:333) com.mchange.v2.c3p0.stmt.GooGooStatementCache - checkinAll(): com.mchange.v2.c3p0.stmt.GlobalMaxOnlyStatementCache stats -- total size: 45; checked out: 0; num connections: 16; num keys: 45 
[2017/05/11 10:06:48] [C3P0PooledConnectionPoolManager[identityToken->2v3o059n1wfndya61hxar|3b29a008]-HelperThread-#1] DEBUG (C3P0PooledConnectionPool.java:283) com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool - com.mchange.v2.c3p0.imp[email protected]58b73780.acquireResource() returning. 
[2017/05/11 10:06:48] [C3P0PooledConnectionPoolManager[identityToken->2v3o059n1wfndya61hxar|3b29a008]-HelperThread-#1] DEBUG (BasicResourcePool.java:1747) com.mchange.v2.resourcepool.BasicResourcePool - trace [email protected] [managed: 17, unused: 1, excluded: 0] (e.g. [email protected]) 
[2017/05/11 10:06:48] [C3P0PooledConnectionPoolManager[identityToken->2v3o059n1wfndya61hxar|3b29a008]-HelperThread-#1] DEBUG (BasicResourcePool.java:471) com.mchange.v2.resourcepool.BasicResourcePool - decremented pending_acquires: 0 
[2017/05/11 10:06:48] [C3P0PooledConnectionPoolManager[identityToken->2v3o059n1wfndya61hxar|3b29a008]-HelperThread-#1] DEBUG (BasicResourcePool.java:1825) com.mchange.v2.resourcepool.BasicResourcePool - Acquisition series terminated successfully. Decremented pending_acquires [0], attempts_remaining: 30 
[2017/05/11 10:06:48] [http-bio-0.0.0.0-20443-exec-4] DEBUG (BasicResourcePool.java:1747) com.mchange.v2.resourcepool.BasicResourcePool - trace [email protected] [managed: 17, unused: 0, excluded: 0] (e.g. [email protected]) 
[2017/05/11 10:06:48] [http-bio-0.0.0.0-20443-exec-4] DEBUG (LogicalConnectionImpl.java:232) org.hibernate.engine.jdbc.internal.LogicalConnectionImpl - Obtained JDBC connection 

public static void updateSignatureLogin(String login, int transactionId) { 
    createEntityManagerFactory(); 
    EntityManager entityManager = entityManagerFactory.createEntityManager(); 
    entityManager.getTransaction().begin(); 
    IsignSignaturetraceEntity dbsignature = entityManager.find(IsignSignaturetraceEntity.class, transactionId); 
    dbsignature.setLogin(login); 
    entityManager.persist(dbsignature); 
    entityManager.merge(dbsignature); 
    entityManager.flush(); 
    entityManager.getTransaction().commit(); 
} 

問題は何ですか:210

そして、これは私がリクエストさせる方法の例はありますか?私が接続/要求をc3p0のコードや設定で管理する方法は?

ありがとうございました。私はここを参照してください

答えて

1

いくつかあります:

  1. あなたはHibernateのセッションの間の接続にハングアップれるのhibernate.connection.release_mode = on_closeを使用しています。その設定の追加オプションについてはこちらをご覧ください:https://access.redhat.com/documentation/en-US/Red_Hat_JBoss_Web_Server/1.0/html/Hibernate_Core_Reference_Guide/transactions-connection-release.html
  2. トランザクションマネージャが手動でトランザクション境界を管理するのではなく、トランザクション境界を手動で管理しています。 Springを使用している場合は、宣言的トランザクション管理をコンフィグレーションできます。詳細については、ここをクリックしてください。http://docs.spring.io/spring-framework/docs/4.2.x/spring-framework-reference/html/transaction.html
  3. 接続プールの最大接続数は20です。それが妥当な数であるかどうかを判断するために、アプリケーションの使用状況データを確認してください。ハードウェアと使用方法によっては、min_sizeの場合でも20接続が低すぎることがあります。
+0

ありがとうございました。私はいくつかのプロパティを変更しました: 'release_mode = after_transaction' ' hibernate.c3p0.timeout = 300'と 'hibernate.c3p0.idle_test_period = 120'。 ログファイルには接続がチェックされていますが、何も変わらないことがわかります。エラーは「最大限に達しました」エラーです。 'com.mchange.v2.resourcepool.BasicResourcePool - 期限切れのリソースを確認します。 com.mchange.v2.resourcepool.BasicResourcePool - 有効期限が切れたリソースを確認しました。 プールはすでに最大値に達しています。 [管理:20; max:20] ' – Moranbzh

+0

私は接続プールが"きれい "ではなく、接続はまだ生きていると思います。私はテストのためにちょうど20の最大接続数を保ってきました。現時点では、解決策ではない最大接続数を増やしてください。いつでもプールが満杯になります。 – Moranbzh

+1

'hibernate.c3p0.timeout'を作成しようとしてください。 - 接続が期限切れになり、大きなファイルと' hibernate.c3p0.idle_test_period'が小さくなった場合、問題を早期に発見することができます。また、プールスレッドがジャムした場合、jstackを使って見ることができます。 – divanov

関連する問題