mysqlへの接続が8時間後に切れる

java.lang.Exception: The last packet successfully received from the server was20910 milliseconds ago.The last packet sent successfully to the server was 20910 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.

(翻訳)

最後の箱はうまくサーバーwas20910から受け取りましたミリ秒、最後の箱がうまくサーバーに送信したago.Theは20910ミリ秒前でした、サーバーが『wait_timeout』の価値を構成したより、長いです。あなたは、どちらの期限切れになっておよび/またはあなたのアプリケーションで使用の前に接続有効性をテストして、クライアントタイムアウトのためにサーバー構成された価値を増やすか、この問題を避けるためにConnector/Jコネクションのプロパティ『autoReconnect=true』を使うことを考慮しなければなりません。

tomcatのウェブアプリケーションでサーブレットを実行したときに上記エラーが発生した。mysqlの設定で、my.cnfファイルには wait_timeout=28800 という設定をしているのだけれど、エラー内容はその値を増やすか、autoReconnect=trueを設定しろということらしい。それをすれば上記エラーは発生しなくなるのかわからないが、とりあえず試してみる。http://www.jajakarta.org/tomcat/tomcat5.0/ja/docs/tomcat-docs/jndi-datasource-examples-howto.htmlのページを参考に、tomcatのコンテキストファイルのデータベース接続urlに

url=”jdbc:mysql://localhost/database?autoReconnect=true

というパラメータを追加した。効果があるかどうかは様子見。

その後

java.net.ConnectException: Connection timed out
        at java.net.PlainSocketImpl.socketConnect(Native Method)
        at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:333)
        at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:195)
        at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:182)
        at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:366)
        at java.net.Socket.connect(Socket.java:519)
        at java.net.Socket.connect(Socket.java:469)

というエラーが発生したのをログにて確認した。context.xmlファイルのデータベース接続情報のパラメータへ、自動再接続の設定を有効にするようにして動作テスト。以下記述例。データベースのurlの末尾に?autoReconnect=trueというパラメータを追加した。この状態で稼動したところ、1日稼動したところデータベースへの接続関連のエラーは発生していないことが確認できた。とりあえずしばらくは様子見。

<Context path=”/” reloadable=”true” docBase=”ROOT”>

<Resource name=”jdbc/db”
auth=”Container”
type=”javax.sql.DataSource”
driverClassName=”com.mysql.jdbc.Driver”
url=”jdbc:mysql://localhost/db?autoReconnect=true”
username=”nakahira”
password=”nakahira-pass”
maxActive=”100″
maxIdle=”100″ />

</Context>

コメントを残す

メールアドレスが公開されることはありません。