3

私の webapp は Tomcat 5.5 で実行されており、web.xml でデータソースを宣言しました。

<resource-ref>
    <res-ref-name>jdbc/OrdiniWebDS</res-ref-name>
    <res-type>javax.sql.DataSource</res-type>
    <res-auth>Container</res-auth>
    <res-sharing-scope>Shareable</res-sharing-scope>
</resource-ref>

context.xml (Tomcat conf):

<Resource 
  auth="Container" 
  driverClassName="com.mysql.jdbc.Driver" 
  maxActive="100" 
  maxIdle="30" 
  maxWait="10000" 
  name="jdbc/OrdiniWebDS" 
  password="[mypassword]" 
  type="javax.sql.DataSource" 
  url="jdbc:mysql://[myHost:port]/ordiniweb" 
  username="[myusername]"
 />

データベースはMySql 5.0です。数時間の「未使用」の後、最初のアクセスでこの例外が発生する場合があることを除いて、すべてが正常に機能します。

com.mysql.jdbc.CommunicationsException: Communications link failure due to underlying exception: 

** BEGIN NESTED EXCEPTION ** 

java.io.EOFException

STACKTRACE:

java.io.EOFException
 at com.mysql.jdbc.MysqlIO.readFully(MysqlIO.java:1956)
 at com.mysql.jdbc.MysqlIO.reuseAndReadPacket(MysqlIO.java:2368)
 at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2867)
 at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1616)
 at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1708)
 at com.mysql.jdbc.Connection.execSQL(Connection.java:3255)
 at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1293)
 at com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:1428)
 at org.apache.tomcat.dbcp.dbcp.DelegatingPreparedStatement.executeQuery(DelegatingPreparedStatement.java:93)
 at com.blasetti.ordiniweb.dao.OrdiniDAO.caricaOrdine(OrdiniDAO.java:263)
...
** END NESTED EXCEPTION **



Last packet sent to the server was 0 ms ago.
 com.mysql.jdbc.MysqlIO.reuseAndReadPacket(MysqlIO.java:2579)
 com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2867)
 com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1616)
 com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1708)
 com.mysql.jdbc.Connection.execSQL(Connection.java:3255)
 com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1293)
 com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:1428)
 org.apache.tomcat.dbcp.dbcp.DelegatingPreparedStatement.executeQuery(DelegatingPreparedStatement.java:93)
 com.blasetti.ordiniweb.dao.OrdiniDAO.caricaOrdine(OrdiniDAO.java:263)
...

リフレッシュする必要があり、再びうまく機能します。何か案が?ありがとう。

4

1 に答える 1

9

MySQL は、反対側が接続を閉じるのを忘れたと想定するため、しばらくすると未使用の接続を削除します。

行う必要があるのは、Tomcat がプールされた接続を再利用する前に適用するチェックを構成することです。これを行う?autoReconnect=true&useUnicode=true&characterEncoding=utf8には、URL の末尾に追加validationQuery="Select 1"し、Resource要素に追加します。

<Resource 
  auth="Container" 
  driverClassName="com.mysql.jdbc.Driver" 
  maxActive="100" 
  maxIdle="30" 
  maxWait="10000" 
  name="jdbc/OrdiniWebDS" 
  password="[mypassword]" 
  type="javax.sql.DataSource" 
  url="jdbc:mysql://[myHost:port]/ordiniweb?autoReconnect=true&useUnicode=true&characterEncoding=utf8" 
  username="[myusername]"
  validationQuery="Select 1"
 />

[編集] このページでは、詳細について説明します: Apache Tomcat での MySQL データソースの構成

于 2010-12-14T08:18:29.577 に答える