mysql already closed._tomcat dbcp 基于jndi当配置java.sql.SQLException: Already closed

最近发现了一个现象,观察到的生产环境,不要有一段时间操作,然后另一个操作,首先将有一个数据库连接:java.sql.SQLException: Already closed.,例如下列:

90ac39556461854348461bdb7ba6c354.png

error log:  ( org.springframework.dao.RecoverableDataAccessException: PreparedStatementCallback; SQL [select user_id,login_name from t_sys_user where login_name=?

and password=?]; The last packet successfully received from the server was1290665 seconds ago.The

last packet sent successfully to the server was 1290665 seconds ago, which 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.; nested exception is com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: The last packet successfully received from the server

was1290665 seconds ago.The last packet sent successfully to the server was 1290665 seconds ago, which 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. )

数据源是用tomcat dbcp 基于jndi配置管理的。查了下。例如以下:

原因:

You're probably running into the fact that MYSQL closes connectionswhich have been open "too long".

Probably if you make the request to the server again, you'll find thatit works because the connection is reopened.

解决方法:

One way to deal with this is to add the following to yourcontext.xmlResource:

validationQuery="select 1"(基于mysql)

validationQuery="select

1 from dual"(基于oracle)

代价:

This causes a very cheap test query to always be run first; if theconnection has been closed, this gets the failure,

and

then a new connection is opened.

细想下原来用weblogic jdbc jndi的配置有一个专门的配置项来配置这个test query,配置tomcat时粗心大意了 :(

[2015-04-30 11:15:46,939 ERROR [com.tencent.vsuning.aop.LogAdvice] - org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection; nested exception is com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException:

Data source rejected establishment of connection,  message from server: "Too many connections"]  数据库连接池耗尽异常...

版权声明:本文博主原创文章,博客,未经同意不得转载。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值