1

私のアプリケーション (Tomcat サーバーで実行) は、atomikos 接続プールを使用して mysql データベースに接続します。アプリケーションサーバーを数時間使用しないと接続がシャットダウンされることを除いて、すべて正常に機能します。以下は、これが発生した後にアプリケーションサーバーを再度操作したときに表示されるエラーメッセージです。

:58:28 AM RusticiSoftware.ScormContentPlayer.Util.Logger LogInfo
INFO: Parsing metadata
Aug 15, 2013 9:58:28 AM RusticiSoftware.ScormContentPlayer.DataHelp.JdbcDataHelper ExecuteReturnDbRows
INFO: ExecuteReturnDbRows: failed - The last packet successfully received from the server was 59,735,409     milliseconds ago.  The last packet sent successfully to the server was 59,735,409 milliseconds ago. 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.

com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: The last packet successfully received from the server was 59,735,409 milliseconds ago.  The last packet sent successfully to the server was 59,735,409 milliseconds ago. 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.
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:411)
at com.mysql.jdbc.SQLError.createCommunicationsException(SQLError.java:1121)
at com.mysql.jdbc.MysqlIO.send(MysqlIO.java:3871)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2484)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2664)
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2815)
at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:2155)
at com.mysql.jdbc.PreparedStatement.execute(PreparedStatement.java:1379)
at RusticiSoftware.ScormContentPlayer.DataHelp.JdbcDataHelper.ExecuteReturnDbRows(JdbcDataHelper.java:453)
..................................
.................................
.................................

Caused by: java.net.SocketException: Broken pipe
at java.net.SocketOutputStream.socketWrite0(Native Method)
at java.net.SocketOutputStream.socketWrite(SocketOutputStream.java:92)
at java.net.SocketOutputStream.write(SocketOutputStream.java:136)
at java.io.BufferedOutputStream.flushBuffer(BufferedOutputStream.java:65)
at java.io.BufferedOutputStream.flush(BufferedOutputStream.java:123)
at com.mysql.jdbc.MysqlIO.send(MysqlIO.java:3852)
... 57 more

jndi パラメータで autoReconnect を true に設定していますが、機能していないようです。

<Resource name="jdbc/ScormEngineDB" auth="Container"
          type="javax.sql.DataSource" driverClassName="com.mysql.jdbc.Driver"
          url="jdbc:mysql://localhost:3306/wgea_scorm?charset=utf8&amp;useUnicode=true&amp;characterEncoding=utf-8&amp;autoReconnect=true"
          factory="org.apache.tomcat.jdbc.pool.DataSourceFactory"
          username="username" password="password" maxActive="20" maxIdle="10" pinGlobalTxToPhysicalConnection="true" testQuery="select 1"
          maxWait="-1" />

また、mysql 側でログを設定したところ、接続が閉じられているため、テスト クエリ (select 1) が実際には mysql に送信されていないことがわかりました。問題が発生すると、毎朝アプリケーションサーバーを再起動する必要があります。

これについてのアイデアはありますか?

ありがとう

4

1 に答える 1

1

最後に、Atomikos 接続プールではなく、Tomcat 接続プールが使用されていることがわかりました。そのため、Tomcat 接続プール パラメータを JNDI 設定で使用する必要があります。次のようになります。

<Resource name="jdbc/ScormEngineDB" auth="Container"
          type="javax.sql.DataSource" driverClassName="com.mysql.jdbc.Driver"
          url="jdbc:mysql://localhost:3306/wgea_scorm?charset=utf8&amp;useUnicode=true&amp;characterEncoding=utf-8&amp;autoReconnect=true"
          factory="org.apache.tomcat.jdbc.pool.DataSourceFactory"
          username="username" password="password" maxActive="20" maxIdle="10" autoReconnectForConnectionPools="true"   
autoReconnectForPools="true"   pinGlobalTxToPhysicalConnection="true" 
<!-- below are Tomcat connection pool parameters-->
testOnBorrow="true" logValidationErrors="true" validationQuery="select 1" testWhileIdle="true" 
testOnConnect="true" validationInterval="3000000" maxWait="-1" />

接続を維持できるように、validationInterval パラメータをデータベース接続タイムアウトよりも短い値に設定できます。autoConnection パラメーターに関しては、推奨されていないため、上記の JNDI 構成から削除できると多くの人が言っています。詳細については、 http://tomcat.10.x6.nabble.com/connection-autoReconnect-td4340944.htmlを参照してください。

于 2013-08-20T11:55:57.173 に答える