Re: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure
Posted by: Lukasz Kwiatkowski
Date: April 11, 2008 01:54AM

Hi
I've got the same problem. I'am using mysql 5.1 and mysql-connector-java-5.1.6-bin.jar in my JBoss 4.2.2 server. After hours of testing i managed to resolve the problem.
First of all it's not a problem of mysql but rather JDBC driver configuration and application code.

To resolve the problem i set testing environment on mysql to

wait_timeout = 80
interactive_timeout = 80

and connection pooling to:

<min-pool-size>4</min-pool-size>
<max-pool-size>20</max-pool-size>
<idle-timeout-minutes>1</idle-timeout-minutes>
<background-validation>true</background-validation>
<background-validation-minutes>1</background-validation-minutes>

for more configuration directive of JBOSS connector see http://wiki.jboss.org/wiki/ConfigDataSources

While i was checking sleeping threads in mysql administrator i discoverd that one of them wasn't renewed after one minute of idle time, but other four worked fine. It was pretty obvious that connection pooling did its job so i went checking my code. I discovered that during the start up of my app i establish one connection to db and did not free it after posting a query. This was the reason why validation proccess did not validate this one connection.

So in my case process was:

1. mysql grabbed sleeping threads after 80 s.
2. connection pooling validation every 1 minute
3. On start up app established one connection to db and therefore removed it from connection pool
4. after 60 seconds 4 connections in the pool validated and therefore idle time restarted
5. The one established connection after 80 seconds of idle time was closed by mysql server
6. my app unawared of that fact still trying to use that one connection and receives error com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure

To resolved the problem i only had to ensure that all open connections are closed imidiately after executing query.

Hope this help.

Options: ReplyQuote


Subject
Written By
Posted
Re: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure
April 11, 2008 01:54AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.