I have a project done with Netbeans 6.9.1, MySQL 5, GWT, Quartz, Javamail and Hibernate (JPA 1.0). I have used Netbeans wizard for creating Entity Classes and JPA controllers. In my development environment I didn't use any Connection Pool, and in the production environment I used C3P0.

The app main task is to launch a Quartz's Job every 5 minutes, and that task calls a Servlet. The Servlet checks emails, parse them, and store them in a database. Basically, the system process emails generated automatically by another system.

I found that after more than 20hours, Java throws a Java Heap Out of Memory message. And also, from time to time, MySQL says it runs out of connection. Attaching a profile to my app. I could see that every time I create a JPA controller, C3P0 is creating a thread com.mchange.v2.async. ThreadPoolAsynchronousRunner$PoolThreadX, where X generally is 0,1,2.

As my process creates 3JPA, every 5 minutes there is a new group of 3 threads "com.mchange.v2.async. ThreadPoolAsynchronousRunner". And when the process finishes, the Threads doesn't disappear, but enters a "WAIT" state. You can imagine that in 24hs I have a lot of threads created, and Java does not release them. More over, the used memory increased but never decreased or stays in the same level.

I think that this behavior, of threads that doesn't exit properly, it is what makes the system out of memory.

This is an example of what my JPA controllers does, when I create one of this objets.

public class RequestJpaController {

    public RequestJpaController() {
        emf = Persistence.createEntityManagerFactory("GVPU");
    private EntityManagerFactory emf = null;

    public EntityManager getEntityManager() {
        return emf.createEntityManager();

    public void create(Request request) {
        EntityManager em = null;
        try {
            em = getEntityManager();
        } finally {
            if (em != null) {

And this is my Persistence.xml file (the only hibernate and c3p0 configuration file that I have).

<?xml version="1.0" encoding="UTF-8"?>
<persistence version="1.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd">
    <persistence-unit name="GVPU" transaction-type="RESOURCE_LOCAL">
            <property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect"/>
            <property name="hibernate.connection.username" value="root"/>
            <property name="hibernate.connection.driver_class" value="com.mysql.jdbc.Driver"/>
            <property name="hibernate.connection.password" value="admin"/>
            <property name="hibernate.connection.url" value="jdbc:mysql://localhost:3306/gv"/>
            <property name="hibernate.cache.provider_class" value="org.hibernate.cache.NoCacheProvider"/>
            <property name="hibernate.connection.provider_class" value="org.hibernate.connection.C3P0ConnectionProvider"/>
            <property name="hibernate.connection.release_mode" value="auto"/>
            <property name="hibernate.connection.aggresive_release" value="true"/>

            <property name="hibernate.c3p0.acquire_increment" value="1"/>
            <property name="hibernate.c3p0.idle_test_period" value="10"/>
            <property name="hibernate.c3p0.debugUnreturnedConnectionStackTraces" value="true"/>
            <property name="hibernate.c3p0.unreturnedConnectionTimeout" value="30"/>
            <property name="hibernate.c3p0.timeout" value="60"/>
            <property name="hibernate.c3p0.max_size" value="120"/>
            <property name="hibernate.c3p0.min_size" value="0"/>
            <property name="hibernate.c3p0.max_statements" value="0"/>


Can anybody tell me what I'm doing wrong?