Using Hibernate 2 and MySql 4.1.20
I have a program that ran constantly (and successfully) for a month when it suddenly just died with no exception info and no stack trace (we print a stack trace when a catchable exception is thrown).
The last thing that we see in the log file is the following error:
WARN [07 Dec 2006 02:11:18] (SessionImpl) unclosed connection
The program runs in a thread which mostly sleeps. It wakes up every minute, does a database call that checks for a particular status on a row in a table and then, if it finds the appropriate status (normally 1/hour), it runs through code which reads our database and writes out some info to a flat file. As mentioned above -- it ran for nearly a full month without any errors or problems.
The program gets one connection upon startup. Then it is in this infinite loop which uses this connection (passing it to the class which does the database reads). At the end of each processing cycle (time through the loop) it does a conn.commit();
There is a finally block which does close the connection -- though it shouldn't really ever hit this as it doesn't really ever stop unless the process is killed.
So basically the code looks like this:
Code:
Connection conn = null;
try {
conn = HibernateUtil.getSession().connection();
do some initialization which includes a few database calls;
while(true) {
get an indicator from the database.
if (indicator set to true) {
do some database reads and write stuff to a flat file
SECONDS.sleep(60);
conn.commit();
}
} catch (Exception e)
e.printStackTrace();
} finally {
if (conn != null) {
try {
conn.close();
} catch (Exception e3) {
e3.printStackTrace();
log.error("could not close connection! "+e3);
}
}
Here is the code for getting the Hibernate Session:
Code:
public static Session getSession() throws HibernateException {
Session s = (Session) threadSession.get();
// Open a new Session, if this Thread has none yet
if (s == null) {
s = sessionFactory.openSession();
threadSession.set(s);
}
return s;
}
Here are the c3p0 settings in my hibernate.cfg file.
<!-- See
http://www.hibernate.org/214.html -->
<property name="c3p0.min_size">5</property>
<property name="c3p0.max_size">30</property>
<property name="c3p0.timeout">30</property>
Any ideas on what may be causing this thread to die?