Hi all. Hope that I am not way off posting in this forum. If so please feel free to direct me to the correct one :)
I have a connection problem. Here goes:
My setup: JBoss-Tomcat 2.4.1/3.2.3, Mysql 3.23.36, mm.mysql-2.0.4.
My Scenario: I connect to Mysql through a lookup to a connection defined i jboss.jcml like so:
<mbean code="org.jboss.jdbc.XADataSourceLoader" name="DefaultDomain:service=XADataSource,name=aDS">
My problem is this: Every now and then I get java.sql.SQLException ->"lost connection during query". If I try the action again it usually fails one more time, then works like a charm. It never fails for more than two times in a row, though.
The mysqld.log indicated that the problem is "Aborted connection XXX to db: 'dbnamn' user: 'dbuser' host: 'dbhost' (Got timeout reading communication packets)"
Anybody know why this happens? Is it a mysql problem? a jdbc problem? Is my jboss.jcml incorrecly configured?
I really have no clue, and would greatly appreciate _any_ pointers.
My guess is your connections are timing out. MySQL closes connections after a period of non-use (usually 8 hours). I would enable your idle timeout, and set it to something less around 5-10 minutes. If you haven't used a connection in that long, no sense in tying up server resources.
Thanks for the pointers.
Am I correct in assuming that the container responsible for these connections (JBoss) should "revive" them as they are needed? If things work as they should, of course.
Do you close your connection in the ejbPassivate() and open it again in the ejbActivate() methods? This could be the reason for the timing out of your connection. I assume that you use Bean Managed Persistence, otherwise it won't make sense.
Well, actually I don't use EJB (with MySQL as datasource at least). This datasource that I am having problems with is only used from Servlets and jsp (through "ordinary" javabeans). What I do is that I open and close the connections here. Is this method wrong?