7

DB接続プーリングにc3p0を使用している永続性レイヤとして、Hibernateを使用してMySQL 5データベースに接続するJavaサーバがあります。Hibernate c3p0接続プールがアイドル接続をタイムアウトしない

私はC3P0以下試してみたとドキュメント休止状態:

を私たちは、生産上のエラーを取得していますサー

... Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: No operations allowed after connection closed.Connection was implicitly closed due to underlying exception/error:

BEGIN NESTED EXCEPTION

com.mysql.jdbc.exceptions.jdbc4.CommunicationsException

MESSAGE: The last packet successfully received from the server was45000 seconds ago.The last packet sent successfully to the server was 45000 seconds ago, which is longer than the server configured value of 'wait_timeout'. You should consider either expiring and/or testing connection validity before use in your application, increasing the server configured values for client timeouts, or using the Connector/J connection property 'autoReconnect=true' to avoid this problem.

STACKTRACE:

com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: The last packet successfully received from the server was45000 seconds ago.The last packet sent successfully to the server was 45000 seconds ago, which is longer than the server configured value of 'wait_timeout'. You should consider either expiring and/or testing connection validity before use in your application, increasing the server configured values for client timeouts, or using the Connector/J connection property 'autoReconnect=true' to avoid this problem.

次のように我々はC3P0接続プールのプロパティを設定しているが:

default MySQL wait_timetoutは28800秒(8時間)に設定されている
hibernate.c3p0.max_size=10 
hibernate.c3p0.min_size=1 
hibernate.c3p0.timeout=5000 
hibernate.c3p0.idle_test_period=300 
hibernate.c3p0.max_statements=100 
hibernate.c3p0.acquire_increment=2 

、報告されたエラーが、それはオーバーをされていると言っていることを示すVERS 45000秒(約12.5時間)。 c3p0の設定では、5000秒後に使用されなかったアイドル状態の接続を「タイムアウト」し、300秒ごとにチェックするため、アイドル状態の接続は5299秒より長くはならないと記載されていますか?

私は開発者MySQL(Windowsの場合はmy.ini、Unixの場合はmy.cnf)をwait_timeout = 60に設定し、c3p0アイドルタイムアウト値を60秒以下に設定してローカルでテストしました。新しいもの。また、私たちがDB接続を漏らしておらず、接続を保持していないことを確認します。それは私たちのようには見えません。

私の開発環境でc3p0.propertiesファイルをテストして、c3p0が接続を適切に処理していることを確認しています。

hibernate.properties(MySQLのWAIT_TIMEOUTでテスト= 60)

hibernate.c3p0.max_size=10 
hibernate.c3p0.min_size=1 
hibernate.c3p0.timeout=20 
hibernate.c3p0.max_statements=100 
hibernate.c3p0.idle_test_period=5 
hibernate.c3p0.acquire_increment=2 

c3p0.properties

com.mchange.v2.log.FallbackMLog.DEFAULT_CUTOFF_LEVEL=ALL 
com.mchange.v2.log.MLog=com.mchange.v2.log.FallbackMLog 
c3p0.debugUnreturnedConnectionStackTraces=true 
c3p0.unreturnedConnectionTimeout=10 
+0

私の答えを見て、hibernate.orgにある互換性マトリックスをチェックしてみてください。(たとえ私がそのマトリックスのc3p0を逃しても) – Schildmeijer

答えて

3

C3P0は本当にによってログを調べ始めていることを確認します。何らかの理由で私のクラスパス上にhibernate(hibernate-core3.3.1.jarとhibernate-3.2.6GA.jar)の2つのバージョンがありました。私は3.2.xと互換性のないハイバネートアノテーションバージョン3.4.0GAも使用しました。 (元の問題と関係があるかどうかは分かりません)。 hibernate jar(削除したことを思い出すことはできません。おそらくhibernate-3.2.6GA.jar)のいずれかを削除した後、最終的にc3p0が起動し、私は厄介なcom.mysql.jdbc.exceptions.jdbc4.CommunicationsExceptionを取り除きました。不活動。

+0

私たちはHibernate 3.2.6 Hibernateと3.4.0GA Hibernateアノテーションを使用しています。 (8時間後にc3p0を処理する場合にのみ問題が発生するか、それ以外の場合は気づくでしょう)。 C3P0が設定されてログに記録されているのが見えています(c3p0.propertiesを使用してログオンすると)。 "[情報] c3p0プールを初期化しています... com.mchange.v2.c3p0。PoolBackedDataSource ... idleConnectionTestPeriod - > 20、、maxIdleTime - > 60 ... " – Dougnukem

+0

3.3.Xへのアップグレードの試行を試してください、上記の組み合わせは、hibernateでサポートされていません(またはダウングレードの休止状態の注釈) – Schildmeijer

+0

は何か試しましたか? – Schildmeijer

関連する問題