2012-03-12 2 views
5

때때로 Java/Tomcat6/Debian Squeeze 애플리케이션이 MySql 서버와 통신 할 수 없습니다. Tomcat 응용 프로그램이 프런트 엔드 서버에 있고 MySql이 별도의 MySql 전용 상자에 있습니다. 일반적인 오류는 다음과 같습니다'autoReconnect = true'인 경우에도 MySql JDBC 시간 초과

com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: The last packet successfully received from the server was56588 milliseconds ago. 

The last packet sent successfully to the server was 56588 milliseconds 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. 

주어진 타임 아웃 시간이 매우 짧은 것 같습니다 60 초입니다. 1 시간 이상이라면 몇 분마다 DB 서버에 ping을 수행하는 백그라운드 작업을 설정하기 만하면됩니다. AutoReconnect 매개 변수를 여는 URL에 추가했습니다. 명백한 영향은 없습니다.

여기에 어떤 문제가 있습니까? 감사합니다 팻

+1

는 링크에 대한이 게시물 http://stackoverflow.com/q/667289/778687 – tusar

+0

@tusar, 감사를 참조하십시오. 내가 왜 코드를 작성해야하는지 설명합니다. 그들은 자동 - reconnect 비하하고있는 흥미 롭군요. – fishtoprecords

+0

서버에 설정된 wait_timeout은 무엇입니까? –

답변

0

네트워크 장애를 코드 작성하고 자동 재 연결을 처리해야합니다.

연결이 끊어졌을 때 자동으로 다시 발생할 수있는 여러 가지 '응용 프로그램'버그로 인해 자동 재 연결이 해제되어 개의 다른 상태로 되돌아옵니다.

어쨌든, 의견은 다소 중복 질문임을 보여줍니다.

0

이 문제를 해결하기 위해 c3p0 속성을 구성하십시오. 사용 속성은 JDBC 연결 URL에

hibernate.connection.provider_class=org.hibernate.connection.C3P0ConnectionProvider 
hibernate.c3p0.min_size=0 
hibernate.c3p0.max_size=20 
hibernate.c3p0.timeout=500 
hibernate.c3p0.max_statements=50 
hibernate.c3p0.idle_test_period=3000 
hibernate.c3p0.testConnectionOnCheckout=true 
hibernate.c3p0.acquire_increment=1 

처럼 url=jdbc:mysql://host/databasename?autoReconnect=true

+0

'autoReconnect'는 더 이상 사용되지 않으며 권장되지 않습니다 ([Connector/J reference] (https://dev.mysql.com/doc/connector-j/5.1/en/connector-j-reference-configuration의 속성 설명 참조). -properties.html # connector-j-reference-set-config) 또는 [15.4 절] 끝에있는 주석 (https://dev.mysql.com/doc/connector-j/5.1/en/connector-j 문제 해결 장의 -usagenotes-troubleshooting.html # qandaitem-15-1-4). [2004] (https://bugs.mysql.com/bug.php?id=5020) 이상이 필요합니다. – vilpan