7

We are using Oracle the UCP driver (Oracle Universal Connection Pool) in tomcat 6. It is more or less configured like in Oracles Howto. The problem is that the driver starts a lot of threads (Thread-0 to 57, UCP-worker-thread-1 to 24) which aren't stopped when the server shuts down - tomcat emits loads of error messages like this:

The web application [/xxx] appears to have started a thread named [Timer-17] but has failed to stop it. This is very likely to create a memory leak.

Any idea how to deal with this?

Dr. Hans-Peter Störr
  • 25,298
  • 30
  • 102
  • 139

1 Answers1

3

I had the same problem and managed to fix this by adding the following code in my ServletContextListener:

import oracle.ucp.admin.UniversalConnectionPoolManager;
import oracle.ucp.admin.UniversalConnectionPoolManagerImpl;

public class MyContextListener implements ServletContextListener {
    /* ... */

    @Override
    public void contextDestroyed(ServletContextEvent sce) {
        // Your shutdown sequence here
        /* ... */

        // Shutdown UCP if present, to avoid warnings about thread leaks
        UniversalConnectionPoolManager ucpManager = UniversalConnectionPoolManagerImpl.getUniversalConnectionPoolManager();
        if (ucpManager != null) {
            String[] poolNames = ucpManager.getConnectionPoolNames();
            if (poolNames != null) {
                for (String poolName : poolNames) {
                    ucpManager.destroyConnectionPool(poolName);
                }
            }
        }
    }

}
ochedru
  • 826
  • 8
  • 17
  • 1
    Reference: see "Controlling the Lifecycle of a Connection" [in Oracle UCP documentation](http://docs.oracle.com/cd/E11882_01/java.112/e12265/manage.htm#BABFBFDE). – ochedru Aug 28 '13 at 13:07
  • 1
    Is there a way of doing this with tomcat configuration only. We have datasources setup in context.xml and don't want to add a compile time dependency in our code to ucp jar – 6ton Jun 07 '18 at 13:00