Hibernate4 + c3p0 + Derby - Memory Leak on Tomcat stop or web application reload

前端 未结 2 1067
南方客
南方客 2020-12-21 02:22

I have a very simple application template which includes an embedded apache derby database through hibernate.

I have the following configuration:

            


        
相关标签:
2条回答
  • 2020-12-21 03:00

    After doing some more research I found that closing explicitely all the connections solves the issue:

    C3P0Registry.getNumPooledDataSources();
    
    @SuppressWarnings({ "unchecked", "rawtypes" })
    Iterator<Set> it = C3P0Registry.getPooledDataSources().iterator();
    while (it.hasNext()) {
        try {
               dataSource = (PooledDataSource) it.next();
               dataSource.close();
        } catch (Exception e) {
               logger.error(e);
        }
    }
    
    0 讨论(0)
  • 2020-12-21 03:06

    A more concise version of the accepted answer that did the trick for me

    for (Object o : C3P0Registry.getPooledDataSources()) {
      try {
        ((PooledDataSource) o).close();
      } catch (Exception e) {
        // oh well, let tomcat do the complaing for us.
      }
    }
    
    0 讨论(0)
提交回复
热议问题