设置:Glassfish 3x,Java EE,EclipseLink。
jdbc连接池配置(来自domain.xml):
<jdbc-connection-pool validation-table-name="dummy" pool-resize-quantity="5" max-pool-size="300" datasource-classname="com.mysql.jdbc.jdbc2.optional.MysqlXADataSource" wrap-jdbc-objects="false" res-type="javax.sql.XADataSource" steady-pool-size="25" name="mysql_bazaarify_rootPool" is-connection-validation-required="true" non-transactional-connections="true" validate-atmost-once-period-in-seconds="60">
<property name="URL" value="jdbc:mysql://demodb.mydb.com:3306/database?zeroDateTimeBehavior=convertToNull&useUnicode=yes"></property>
很少为不同的查询获取CommunicationsException。 我已配置要在使用前经过60秒有效期验证的连接。 sql server上的wait_time是8个小时。
仍然在日志中看到以下错误(每天约50次) 异常跟踪:
Internal Exception:
com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: No operations allowed after connection closed.
Error Code: 0
....
Caused by: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException:
The last packet successfully received from the server was 56,688,227 milliseconds ago.
The last packet sent successfully to the server was 56,688,227 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.
....
Caused by: java.net.SocketException: Connection timed out
at java.net.SocketOutputStream.socketWrite0(Native Method)
at java.net.SocketOutputStream.socketWrite(SocketOutputStream.java:113)
at java.net.SocketOutputStream.write(SocketOutputStream.java:159)
at java.io.BufferedOutputStream.flushBuffer(BufferedOutputStream.java:82)
at java.io.BufferedOutputStream.flush(BufferedOutputStream.java:140)
at com.mysql.jdbc.MysqlIO.send(MysqlIO.java:3832)
... 140 more
我的问题是,当我设置要验证的连接(每60秒)时,是否有可能从连接池中获得陈旧/断开的连接,该连接说与mysql的最后一次通信是(> 60seconds)之前?
在从池中返回正常连接之前,是否应该验证连接?这些例外与我配置的设置是否正常?
P.S。 我观察到,在所有此类故障中,报告的毫秒前值始终> 8小时。这有助于推断出什么吗?