しばらくの間(数時間)、CommunicationsExceptionを取得しています(DBCPから)。エラーメッセージ(Exception内)はこの質問の最後ですが、設定ファイルのいずれかで定義されたwait_timeoutは表示されません。 (どこから見えるのですか?tomcat/confディレクトリのどこかにありますか?)DBCPを使用したTomcatの設定
第2に、Exceptionで提案されているように、「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)
これらは、私たちの一部は、ある理由からですIDEの設定やDriverManager.getConnection(...)がより信頼できるかもしれない魔法のような魔法に依存するかもしれません。それに関するコメント?あなたの洞察をいただきありがとうございます - MS
私が正しく理解していれば、DBCPはプール内の接続を維持しますが、mySqlサーバーはタイムアウトします。この接続アプリに送信された場合、閉じた接続です。意味がありますが、それは私の正しい理解ですか?もう一つの質問:あなたが述べたようにvalidationQuery/testOnBorrowを使う上で、また、context.xmlファイルのtestWhileIdleとautoRecon ...の使用には何か問題はありませんか?彼らはそのファイルに入っていますよね? –
1.ご理解の方。私が指摘したすべてのソリューションは相補的です。 1つを設定することは、他の設定を妨げるものではありません。ベルトとブレースはより良い;-)私は3つのソリューションをすべて実装します。アイドル状態でのテストは、「借り」時間で待ち時間が短くなることを意味します。プロパティの設定は、不適切な切断を減らします。はい、それらはすべてあなたのwebappのcontext.xml(後で$ CATALINA_HOME/conf/Catalina/localhost/yourwebapp.xmlのtomcatによってデプロイされます)のResource部分に入ります。 –
autoReconnectは推奨されていません - http://dev.mysql.com/doc/refman/5.0/en/connector-j-reference-configuration-properties.html – OrangeDog