Two Laptop Bag
The moose likes JDBC and Relational Databases and the fly likes wait _ timeout breaks connection (mysql related) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "wait _ timeout breaks connection (mysql related)" Watch "wait _ timeout breaks connection (mysql related)" New topic

wait _ timeout breaks connection (mysql related)

Yucca Nel
Ranch Hand

Joined: Nov 20, 2008
Posts: 147

Need a little help here if possible....

1) I am using hibernate with mysql and tomcat 6.
2) I wish to alter the default 8 hour wait time that mysql comes with.
3) In doing so I have modifies my /etc/my.inf to include the lines:


I then do a restart of mysql server and a show variable query on timout to confirm that the values on no longer defaults.

My system then breaks as tomcat is not able to use hibernate pool for authentication and aditionally the following happens:

I create a new 'test' user and the application works. Additionally trying to recreate the user brings about the necassary exceptions I have defined, indicating that the new test user is sitting in the cache but is never flushed.

Removing the configuration I did makes it work again but I then have to deal with the 8 hour timeout again.

Many thanks for any help.

SCJP 6.0, SCJD (400/400), SCBCD for JEE 5, SCWCD 1.4 I do videos for development at
I am probably the only developer ever to have had an orange sized brain tumor in my brain while learning development!!
David O'Meara

Joined: Mar 06, 2001
Posts: 13459

My system then breaks as tomcat is not able to use hibernate pool for authentication and aditionally the following happens:

It is not clear why this breaks

The 'standard' solution is to the use the autoReconnect=true on the JDBC URL, and additionaly to specify for the DB pool to testOnBorrow true and set a validation query.
The problem here has several levels. Firstly there is the issue that MySQL times out connections that are idle for 8 hours (by default). Changing this value can help a little but is more of a hack than a solution.
The next problem is that the pool is unaware of bad Connections unless you tell it that a Connection has gone bad. The autoReconnnect setting setting tells the MySQL Driver to recreate any connections that fail, and by using the testOnBorrow, you allow the connection to fail and be recreated before the connection gets passed to your application.

While autoReconnect=true is no longer the preferred solution, I haven't had much luck with the 'reconnect for polled connection' setting (I forget what it is called).
I agree. Here's the link:
subject: wait _ timeout breaks connection (mysql related)
It's not a secret anymore!