Home >Database >Mysql Tutorial >Mysql的wait_timeout解决_MySQL

Mysql的wait_timeout解决_MySQL

WBOY
WBOYOriginal
2016-06-02 08:49:494114browse

bitsCN.com


Mysql的wait_timeout解决

 

问题:

ssh+mysql项目,数据源为dbcp,隔夜后访问会出现下列错误

1

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

2

...

原因:

 

mysql存在一项属性“wait_timeout”,默认值为28800秒(8小时),

通过下面口令可以查看

 

1

mysql> show global variables like 'wait_timeout';

其意思为mysql的一个connection空闲时间超过8小时,mysql会自动断开该连接。 

由于dbcp没有检验该connection是否有效,所以用其进行数据操作便会出现异常。

 

解决方法:

修改dbcp配置:

 

1

timeBetweenEvictionRunsMillis = 20000 

2

minEvictableIdleTimeMillis = 28700

“timeBetweenEvictionRunsMillis ”  dbcp每2000秒进行一次connection的检验, 

“minEvictableIdleTimeMillis ” 每次检验中将超过28700秒处于空闲的connection断开

 

bitsCN.com
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn