This week's book giveaway is in the Mac OS forum. We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line! See this thread for details.
This works fine most of the time, even under high use/pressure... However...if I leave the program running but idle for an extended
while... where basically it's just in a listening state and none of the
connections are getting taken and they are all residing in the
Pool...whenever a new message arrives and it requires a connection to the DB
i always get error:
mysql.jdbc.exceptions.jdbc4.Communicat... Communication link
A program restart will fix immediately. I'm guessing the idle time is the key here with
the connections somehow dying, getting corrupt, exceeded time to live
etc or something...? but I've no idea how to fix...
the best way to fix it, is to use one of the existing connection pooling libraries. They have built in mechanisms to check connection health before giving the connection to your application.
You could build in this functionality in your own connection pool:
Before handing over a connection, execute a small sql statement with that connection.
If it returns, you can give the connection to the application.
If it fails, throw away the connection, replace it with a fresh one, and give it to the application.