9

しばらく(数時間)待機した後、CommunicationsException(DBCPから)が発生します。(例外の)エラーメッセージはこの質問の最後にありますが、どの構成ファイルにもwait_timeoutが定義されていません。(どこを見ればよいですか?tomcat / confディレクトリのどこかですか?)

次に、例外で示唆されているように、「Connector/J接続プロパティ'autoReconnect= true'」はどこに配置しますか?tomcatセットアップのファイルconf/context.xmlのリソース定義は次のとおりです。

<Resource name="jdbc/TomcatResourceName" auth="Container" type="javax.sql.DataSource"
           maxActive="100" maxIdle="30" maxWait="10000"
           removeAbandoned="true" removeAbandonedTimeout="60" logAbandoned="true"
           username="xxxx" password="yyyy"
           driverClassName="com.mysql.jdbc.Driver"
           url="jdbc:mysql://127.0.0.1:3306/dbname?autoReconnect=true"/>

第三に、JVMがexecuteQuery()の呼び出しを待って例外をスローするのはなぜですか?接続がタイムアウトした場合、getConnectionメソッドは例外をスローする必要がありますね。これは私が話しているソースコードのセクションです:

        try {
                conn = getConnection (true);
                stmt = conn.createStatement (ResultSet.TYPE_SCROLL_INSENSITIVE,
                                                ResultSet.CONCUR_READ_ONLY);
                rset = stmt.executeQuery (bQuery);
                while (rset.next()) {
                     ....

最後に、スタックトレースの最初の数行を示します...

com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: The last packet successfully received from the server was 84,160,724 milliseconds ago.  The last packet sent successfully to the server was 84,160,848 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:57)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:532)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:406)
at com.mysql.jdbc.SQLError.createCommunicationsException(SQLError.java:1074)
at com.mysql.jdbc.MysqlIO.send(MysqlIO.java:3291)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1938)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2107)
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2642)
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2571)
at com.mysql.jdbc.StatementImpl.executeQuery(StatementImpl.java:1451)
at org.apache.tomcat.dbcp.dbcp.DelegatingStatement.executeQuery(DelegatingStatement.java:208)

これらが、「dbcpを忘れて、IDE構成と内部の魔法に依存しているため、DriverManager.getConnection(...)の方が信頼性が高い」と考える理由です。それについて何かコメントはありますか?あなたの洞察に感謝します、-MS

4

2 に答える 2

14

DBCPは、今後の接続要求に対して返されたmysql接続を開いたままにするため、MySQLサーバーのタイムアウトの犠牲になります。

DBCPには、役立つ多くの機能があります(Tomcat 5.5 IIRC以降で使用できます)。

validationQuery="SELECT 1"
testOnBorrow="true"

検証では、「borrow」メソッドを実行するWebアプリケーションに接続を返す前に、接続が有効であることを確認します。もちろん、フラグはこの機能を有効にします。

タイムアウト(私が信じる8時間)が経過し、接続が切断された場合、新しい接続がテストされ(もう存在しない場合は作成されます)、Webアプリに提供されます。

その他の可能なアプローチ:

  1. testWhileIdle="true"リソース設定でDBCPを使用して、有効な要求が検出される前にアイドル状態の接続も確認します。

  2. 'connectionProperties'を使用して、MySQL接続を強化します(例autoReconnect/autoReconnectForPools=true

于 2011-02-09T21:28:47.323 に答える
0

DBCPは本番環境での使用を目的としたものではなく、作成者でさえそう言っています(このプレゼンテーションを参照してください:http://www.infoq.com/presentations/Tuning-Tomcat-Mark-Thomas)。

C3P0をご覧になることをお勧めします: http://www.mchange.com/projects/c3p0/index.html

于 2011-02-09T21:09:15.220 に答える