Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Oracle UCP driver and tomcat: threads failing to stop

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?

like image 601
Hans-Peter Störr Avatar asked Mar 12 '12 16:03

Hans-Peter Störr


1 Answers

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);
                }
            }
        }
    }

}
like image 90
ochedru Avatar answered Nov 15 '22 00:11

ochedru