I am facing a similar problem as the OP with JPA/Hibernate/MSSQL/jtds/c3p0 on Windows XP.
Following code is scheduled to run periodically, every 2 minutes.
---------------------------------------------------------------------------------------
Code:
public class Sender extends TimerTask {
private static EntityManager em;
private static EntityManagerFactory factory;
public void run() {
em = factory.createEntityManager();
EntityTransaction tx = em.getTransaction();
try
{
tx.begin();
/* Query db and do email sending work here */
tx.commit();
}catch(Exception ex)
{
if(tx.isActive())
{
tx.rollback();
}
}
finally
{
em.close();
}
}
}
---------------------------------------------------------------------------------------
Even when there are no results returned and nothing to send, Activity Monitor shows that
'CPU' and 'Physical IO' increased.
Shouldn't em.close(); cause the connection to be cleared from the list of processes
during the 2minutes prior to the next pass? Right now, it never is and the figures soon run into the 10,000 to 20,000.
I've also tested with combinations of OpenJPA, PostgreSQL, MS JDBC Driver 3.0.
Same thing. pg_stat_activity on PostgreSQL reports the connection as long as my app is running.
Either I'm doing something wrong in the code, or it's the expected behaviour.