Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

wait _ timeout breaks connection (mysql related)

 
Yucca Nel
Ranch Hand
Posts: 147
IntelliJ IDE Java Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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:

interactive_timeout=604800
interactive_timeout=604800

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.
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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).
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic