C3p0 says - "java.lang.Exception: ON DEBUGE: Overdue resource stack trace" when starting a sleep transaction

Recently, my cat began to hang out. Requests never answered. I realized that this is due to the fact that connections do not return to the connection pool.

I used c3p0 with hibernate and the database is mysql 5.5

To debug connection leaks, I added the following properties to my hibernate.cfg.xml

 <property name="hibernate.c3p0.unreturnedConnectionTimeout">30</property>
        <property name="hibernate.c3p0.debugUnreturnedConnectionStackTraces">true</property>

After adding them, the magazines say:

[2013-10-12 23:40:22.487] [ INFO] BasicResourcePool.removeResource:1392 - A checked-out resource is overdue, and will be destroyed: com.mchange.v2.c3p0.impl.NewPooledConnection@1f0c0dd
[2013-10-12 23:40:22.487] [ INFO] BasicResourcePool.removeResource:1395 - Logging the stack trace by which the overdue resource was checked-out.
java.lang.Exception: DEBUG ONLY: Overdue resource check-out stack trace.

Indication of at dao.DAOBasicInfo.getBean(DAOBasicInfo.java:69)

public static Basicinfo getBean(Integer iduser) {
        Basicinfo u = null;
        Session sess = NewHibernateUtil.getSessionFactory().openSession();
        try {
            Transaction tx = sess.beginTransaction();   //line 69
            Query q = sess.createQuery("from Basicinfo where iduser=" + iduser);
            u = (Basicinfo) q.uniqueResult();
            if (u == null) {
                u = new Basicinfo();
                u.setIduser(iduser);
            }
            tx.commit();
        } catch (Exception ex) {
            ex.printStackTrace();
        } finally {
            sess.close();
        }
        return u;
    }

I crossed myself and Mysql claims to support transactions with InnoDB

Due to the above error, I have unsent connections, and then they accumulate, making the application immune.

Please let me know what is wrong when starting a transaction, and even I use, finally, and there were no exceptions.

+4
2

  • . , , unverturnedConnectionTimeout.

  • , . , . , . unverturnedConnectionTimeout, , .

  • . tx.setTimeout(20) - , - .

  • . VisualVM Java. ( linux mac) Java Debugging java. JDK.

  • , , . ​​ catch tx.close, .

  • ​​ . , , , , - . , , finally, , , .

  • - . , , uid . if (u == null). , , .

    public static Basicinfo getBean(Integer iduser) {
    Basicinfo u = null;
    Transaction tx = null;
    Session sess = NewHibernateUtil.getSessionFactory().openSession();
    try {

        Query q = sess.createQuery("from Basicinfo where iduser=" + iduser);
        u = (Basicinfo) q.uniqueResult();
        if (u == null) {
            tx = sess.beginTransaction();   //line 69
            u = new Basicinfo();
            u.setIduser(iduser);
            tx.commit();
        }           
    } catch (Exception ex) {
        ex.printStackTrace();
        if(tx != null) {
            try {
             tx.rollback();
            } catch(Exception e){e.printStackTrace;}
        }
    } finally {
        if(sess!=null) {
         sess.close();
        }
    }
    return u;
}
+4

,

transaction.commit();

, -, , ,

+2

All Articles