2012-03-12 49 views
6

我們在tomcat 6中使用Oracle UCP驅動程序(Oracle Universal Connection Pool)。它或多或少地配置爲像Oracles Howto一樣。問題是驅動程序啓動了很多線程(線程0到57,UCP-worker-thread-1到24),這些線程在服務器關閉時不會停止 - tomcat發出如下所示的大量錯誤消息:Oracle UCP驅動程序和tomcat:線程無法停止

Web應用程序[/ xxx]似乎已經啓動了一個名爲 [Timer-17]的線程,但未能阻止它。這很可能會造成內存泄漏。

任何想法如何處理這個?

回答

2

我有同樣的問題,並設法通過我的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); 
       } 
      } 
     } 
    } 

} 
+0

參考:請參閱「控制連接的生命週期」甲骨文UCP文檔中(HTTP:/ /docs.oracle.com/cd/E11882_01/java.112/e12265/manage.htm#BABFBFDE)。 – ochedru 2013-08-28 13:07:16