Abbiamo un server java che si connette a un database MySQL 5 usando Hibernate come livello di persistenza che utilizza c3p0 per il pooling di connessioni DB.Hibernate c3p0 pool di connessioni non ha temporizzato connessioni inattive
ho provato in seguito alla c3p0 e Hibernate documentazione:
Stiamo ottenendo un errore sulla nostra produzione ser vers affermando che:
... 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.
Noi abbiamo la nostra connessione c3p0 proprietà del pool di configurazione come segue:
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
Il default MySQL wait_timetout è impostato su 28800 secondi (8 ore), l'errore segnalato sta dicendo che è passato più di 45000 secondi (circa 12,5 ore). Sebbene la configurazione c3p0 dichiari che eseguirà "timeout" connessioni inattive che non sono state utilizzate dopo 5000 secondi e controllerà ogni 300 secondi, quindi una connessione inattiva non dovrebbe mai durare più a lungo di 5299 secondi, giusto?
Ho provato localmente impostando il mio sviluppatore MySQL (my.ini su windows, my.cnf su Unix) wait_timeout = 60 e abbassando i valori di timeout di inattività c3p0 inferiori a 60 secondi, e andrà in timeout correttamente le connessioni inattive e creerà nuovi. Verifico anche che non stiamo perdendo connessioni DB e stiamo trattenendo una connessione, e non sembra che lo siamo.
Ecco il file c3p0.properties che sto utilizzando per testare nel mio ambiente di sviluppo per garantire che c3p0 gestisca correttamente le connessioni.
hibernate.properties (test con 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
vedere la mia risposta e controllare anche la matrice di compatibilità ubicata su hibernate.org (anche se mi manca c3p0 in quella matrice) – Schildmeijer