users@glassfish.java.net

Communication link failure - problem with short Mysql server timeout

From: <glassfish_at_javadesktop.org>
Date: Fri, 23 Jul 2010 03:06:54 PDT

Hi all,
I have a timer bean that trigger some function periodically, that function makes some tasks on entities whose are persisted to mysql server. Simple scenario :)
In development environment all worked fine. Problems occurred in production.
After some investigation I figured out the reason. The hosting provider setup mysql server:
interactive_timeout = 300
wait_timeout = 120
what means each connection was finished by mysql server after 2 minutes.
The problem is glassfish thinks that connections are valid and try to use it.
Validation in connection pool doesn't solve the problem because first GF try to connect, makes some exceptions then waits 10 seconds and make a new now good connection. For me it looks as dirty solution.

I get:
INFO: Communication failure detected when attempting to perform read query outside of a transaction. Attempting to retry query.
INFO: Communication failure detected when attempting to perform read query outside of a transaction. Attempting to retry query.
INFO: Communication failure detected when attempting to perform read query outside of a transaction. Attempting to retry query.
INFO: Communication failure detected when attempting to perform read query outside of a transaction. Attempting to retry query.
and then:
Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.1.0.v20100311-r6779): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure
The last packet successfully received from the server was 315 390 milliseconds ago. The last packet sent successfully to the server was 0 milliseconds ago.

In code I use only

@PersistenceContext(unitName="SomeName-ejbPU")
public EntityManager em;
then
Query q1 = em.createNamedQuery(....);
em.persist(someEntity);
em.clear();

How can I close connection from app or force to use permanent connection to mysql server or first check if connection is valid then try to connect via it. I noticed that each operation on some entity makes new connection to mysql server ;/

Pleas point me to right place or suggest some solution.

thx
Pshemol
[Message sent by forum member 'pshemol']

http://forums.java.net/jive/thread.jspa?messageID=478378