【问题标题】:Oracle UCP driver and tomcat: threads failing to stopOracle UCP 驱动程序和 tomcat:线程无法停止
【发布时间】:2012-03-29 02:24:45
【问题描述】:

我们在 tomcat 6 中使用 Oracle UCP 驱动程序(Oracle 通用连接池)。它的配置或多或少类似于 Oracles Howto。问题是驱动程序启动了很多线程(Thread-0 到 57,UCP-worker-thread-1 到 24),这些线程在服务器关闭时并未停止 - tomcat 会发出大量错误消息,如下所示:

Web 应用程序 [/xxx] 似乎启动了一个名为 [Timer-17] 但未能阻止它。这很可能会创建一个 内存泄漏。

知道如何处理吗?

【问题讨论】:

    标签: oracle tomcat tomcat6 ucp


    【解决方案1】:

    我遇到了同样的问题,并通过在我的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);
                    }
                }
            }
        }
    
    }
    

    【讨论】:

    • 参考:参见“控制连接的生命周期”in Oracle UCP documentation
    • 有没有办法只使用 tomcat 配置来做到这一点。我们在 context.xml 中设置了数据源,并且不想在我们的代码中添加编译时依赖项到 ucp jar
    猜你喜欢
    • 2014-11-28
    • 1970-01-01
    • 2013-05-02
    • 2016-05-27
    • 2013-05-08
    • 2012-11-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多