关闭

mysql dbcp 自动断开

385人阅读 评论(0) 收藏 举报
分类:

一项目用Mysql+S2SH,数据源用dbcp,部署好后,运行了一夜吧,第二天就报错,log显示大致就是

System Runtime Error:

Could not open Hibernate Session for transaction; nested exception is org.hibernate.TransactionException: JDBC begin failed:

javax.servlet.ServletException: Could not open Hibernate Session for transaction; nested exception is org.hibernate.TransactionException: JDBC begin failed: at org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:515) at org.apache.struts2.dispatcher.FilterDispatcher.doFilter(FilterDispatcher.java:419) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173) at org.springframework.orm.hibernate3.support.OpenSessionInViewFilter.doFilterInternal(OpenSessionInViewFilter.java:198) at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:75) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173) at com.buptnu.usermanage.filter.LoginFilter.doFilterInternal(LoginFilter.java:58) at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:75) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148) at org.apache.jk.server.JkCoyoteHandler.invoke(JkCoyoteHandler.java:199) at org.apache.jk.common.HandlerRequest.invoke(HandlerRequest.java:282) at org.apache.jk.common.ChannelSocket.invoke(ChannelSocket.java:767) at org.apache.jk.common.ChannelSocket.processConnection(ChannelSocket.java:697) at org.apache.jk.common.ChannelSocket$SocketConnection.runIt(ChannelSocket.java:889) at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:684) at java.lang.Thread.run(Thread.java:595)


 

 

 Mysql服务器默认的“wait_timeout”是28800秒,即为8小时,也就是说一个connection空闲超过8个小时,Mysql将自动断开该 connection。connections如果空闲超过8小时,Mysql将其断开,而DBCP并不知道该connection已经失效,如果这时有 Client请求connection,DBCP将该失效的Connection提供给Client,将会造成上面的异常。
        mysql配置中的wait_timeout值一定要大于等于连接池种的idle_timeout 值。否则mysql会在wait_timeout的时间后关闭连接,然而连接池还认为该连接可用,这样就会产生异常。

mysql中如何查看wait_timetout:进入mysql命令  输入命令:

mysql> show global variables like 'wait_timeout';

 一般不建议修改mysql默认的wait_timeout值。

 

直接在dbcp的配置中简单配置即可:

6.timeBetweenEvictionRunsMillis = 20000
  //这个值要小于mysql中的 'wait_timeout' 28800 
7.minEvictableIdleTimeMillis = 28000


 

timeBetweenEvictionRunsMillis毫秒秒检查一次连接池中空闲的连接,把空闲时间超过minEvictableIdleTimeMillis毫秒的连接断开,直到连接池中的连接数到minIdle为止


参考:http://blog.csdn.net/tonychanhoho/article/details/7521876

0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:27917次
    • 积分:484
    • 等级:
    • 排名:千里之外
    • 原创:19篇
    • 转载:16篇
    • 译文:0篇
    • 评论:5条
    文章分类
    最新评论