Oracle UCP 驱动程序和 tomcat:线程无法停止 [英] Oracle UCP driver and tomcat: threads failing to stop
问题描述
我们在 tomcat 6 中使用 Oracle UCP 驱动程序(Oracle 通用连接池).它或多或少像在 Oracles 中配置 操作方法.问题是驱动程序启动了很多线程(Thread-0 到 57,UCP-worker-thread-1 到 24),这些线程在服务器关闭时不会停止——tomcat 会发出大量的错误消息,如下所示:><块引用>
Web 应用程序 [/xxx] 似乎启动了一个名为[Timer-17] 但未能阻止它.这很可能会创建一个内存泄漏.
知道如何处理这个问题吗?
我遇到了同样的问题,并通过在我的 ServletContextListener
中添加以下代码设法解决了这个问题:
import oracle.ucp.admin.UniversalConnectionPoolManager;导入 oracle.ucp.admin.UniversalConnectionPoolManagerImpl;公共类 MyContextListener 实现 ServletContextListener {/* ... */@覆盖公共无效 contextDestroyed(ServletContextEvent sce) {//你的关机顺序在这里/* ... *///关闭 UCP(如果存在),以避免有关线程泄漏的警告UniversalConnectionPoolManager ucpManager = UniversalConnectionPoolManagerImpl.getUniversalConnectionPoolManager();如果(ucpManager != null){String[] poolNames = ucpManager.getConnectionPoolNames();如果(池名称!= null){for (String poolName: poolNames) {ucpManager.destroyConnectionPool(poolName);}}}}}
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?
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);
}
}
}
}
}
这篇关于Oracle UCP 驱动程序和 tomcat:线程无法停止的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!