Question

I am integrating Hibernate 4 with BoneCP and wanted to understand what these properties mean:

<property name="idleConnectionTestPeriod">30</property>
<property name="idleMaxAge">240</property>
<property name="connectionTestStatement">select 1 from db.table limit 1</property>

My application is one which needs to maintain constant connection to the mysqldb 24x7

Does it mean that every 30 minutes the test statement will get executed? and that connection will become stale after 240 minutes ? How do I make my connections permanent because with this configuration occasionally I am getting

Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: No operations allowed after connection closed.
Was it helpful?

Solution

As the author of the BoneCP wrote here, there are 2 ways to manage connections state - the way you use and just setting maxConnectionAgeInSeconds.

Important note - don't forget about MySQL configuration such as wait_timeout. It given in seconds and must be greater than maxConnectionAgeInSeconds. You can change this parameter in my.ini file in MySQL's directory.

For example, my current configuration:
wait_timeout=3600 (MySQL parameter);
maxConnectionAgeInSeconds=3000 (BoneCP parameter)

Also, I set interactive_timeout variable the same with wait_timeout. I'm not sure does it make sense but I saw somewhere MySQL takes min(interactive_timeout,wait_timeout). Actually, interactive_timeout is timeout for interactive clients - when you use MySQL command line you are interactive client. Anyway, it's better to make them equal - even this parameter doesn't make sense it's something like insurance.

P.S. Don't forget turn off mysql (cmd->net stop mysql) before setting variables. After setting new values check them in command line using show variables like '%timeout%';

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top