1. 问题:日志中出现下面的警告:

警告: The web application [ROOT] appears to have started a thread named [HouseKeeper] but has failed to stop it. This is very likely to create a memory leak. Stack trace of thread:
java.lang.Thread.sleep(Native Method)
org.logicalcobwebs.proxool.HouseKeeperThread.run(HouseKeeperThread.java:46)

2. 原因调查:

使用的是 proxool 连接池,查看源码,分析如下:

在项目某种情况下,ProxoolFacade.shutdown(); 被调用,他会调用:

    protected static void shutdown(String finalizer, int delay) {

        ConnectionPool[] cps = ConnectionPoolManager.getInstance().getConnectionPools();
for (int i = 0; i < cps.length; i++) {
removeConnectionPool(finalizer, cps[i], delay);
} // If a shutdown hook was registered then remove it
try {
if (shutdownHook != null) {
ShutdownHook.remove(shutdownHook);
}
} catch (Throwable t) {
if (LOG.isDebugEnabled()) {
LOG.debug("Unanticipated error during removal of ShutdownHook. Ignoring it.", t);
}
} // Stop threads
PrototyperController.shutdown();
HouseKeeperController.shutdown(); }

这里 首先 关闭连接池,然后在最后面关闭了一个 housekeeper 的 demaon线程:

 HouseKeeperController.shutdown();
    /**
* Stop all house keeper threads.
*/
protected static void shutdown() {
synchronized(LOCK) {
Iterator i = houseKeeperThreads.iterator();
while (i.hasNext()) {
HouseKeeperThread hkt = (HouseKeeperThread) i.next();
LOG.info("Stopping " + hkt.getName() + " thread");
hkt.cancel();
}
houseKeeperThreads.clear();
}
}

对每一个 housekeeper 线程调用 cancel() 方法,一般只有一个 housekeeper线程:

hkt.cancel();
public class HouseKeeperThread extends Thread {
private static final Log LOG = LogFactory.getLog(HouseKeeperThread.class);
private boolean stop;
public HouseKeeperThread(String name) {
setDaemon(true);
setName(name);
}
public void run() {
while (!stop) {
HouseKeeper hk = HouseKeeperController.getHouseKeeperToRun();
while (hk != null && !stop) {
try {
// if (LOG.isDebugEnabled()) {
// LOG.debug("About to sweep " + hk.getAlias());
// }
hk.sweep();
} catch (ProxoolException e) {
LOG.error("Couldn't sweep " + hk.getAlias(), e);
}
hk = HouseKeeperController.getHouseKeeperToRun();
}
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
LOG.error("Interrupted", e);
}
}
}
protected void cancel() {
stop = true;
}
}

尼玛 stop 尽然是一个 普通 的 boolean 变量,感觉应该使用 volatile 修饰!

保错的原因是,housekeeper 线程因为每隔5秒执行一次,而系统 想要 stop 它的时候,它正在 sleep ,所以抛出了异常:

警告: The web application [ROOT] appears to have started a thread named [HouseKeeper] but has failed to stop it. This is very likely to create a memory leak. Stack trace of thread:
java.lang.Thread.sleep(Native Method)
org.logicalcobwebs.proxool.HouseKeeperThread.run(HouseKeeperThread.java:46)

但是,因为 设置了 stop = true,所以,当它 sleep 完成之后,也可能会 判断 stop == true, 也可能判断 stop == false,因为这里没有使用 volatile 修饰!

所以最坏的结果,就是 有一个名叫 "HouseKeeper" 的 deamon jvm 线程没有被成功关闭。

3. 日志显示,数据库连接池,确实被正确关闭了:

ContainerBackgroundProcessor[StandardEngine[Catalina]] - Proxool shoutdown
[INFO ] org.logicalcobwebs.proxool.ConnectionPool.shutdown(ConnectionPool.java:484):ContainerBackgroundProcessor[StandardEngine[Catalina]] - Shutting down 'autumn' pool immediately [ContainerBackgroundProcessor[StandardEngine[Catalina]]]
[DEBUG] org.logicalcobwebs.proxool.ConnectionPool.removeProxyConnection(ConnectionPool.java:441):ContainerBackgroundProcessor[StandardEngine[Catalina]] - 000003 (00/05/00) - #0006 removed because of shutdown.
[DEBUG] org.logicalcobwebs.proxool.ConnectionPool.shutdown(ConnectionPool.java:547):ContainerBackgroundProcessor[StandardEngine[Catalina]] - Connection #6 closed
[DEBUG] org.logicalcobwebs.proxool.ConnectionPool.removeProxyConnection(ConnectionPool.java:441):ContainerBackgroundProcessor[StandardEngine[Catalina]] - 000003 (00/04/00) - #0005 removed because of shutdown.
[DEBUG] org.logicalcobwebs.proxool.ConnectionPool.shutdown(ConnectionPool.java:547):ContainerBackgroundProcessor[StandardEngine[Catalina]] - Connection #5 closed
[DEBUG] org.logicalcobwebs.proxool.ConnectionPool.removeProxyConnection(ConnectionPool.java:441):ContainerBackgroundProcessor[StandardEngine[Catalina]] - 000003 (00/03/00) - #0004 removed because of shutdown.
[DEBUG] org.logicalcobwebs.proxool.ConnectionPool.shutdown(ConnectionPool.java:547):ContainerBackgroundProcessor[StandardEngine[Catalina]] - Connection #4 closed
[DEBUG] org.logicalcobwebs.proxool.ConnectionPool.removeProxyConnection(ConnectionPool.java:441):ContainerBackgroundProcessor[StandardEngine[Catalina]] - 000003 (00/02/00) - #0003 removed because of shutdown.
[DEBUG] org.logicalcobwebs.proxool.ConnectionPool.shutdown(ConnectionPool.java:547):ContainerBackgroundProcessor[StandardEngine[Catalina]] - Connection #3 closed
[DEBUG] org.logicalcobwebs.proxool.ConnectionPool.removeProxyConnection(ConnectionPool.java:441):ContainerBackgroundProcessor[StandardEngine[Catalina]] - 000003 (00/01/00) - #0002 removed because of shutdown.
[DEBUG] org.logicalcobwebs.proxool.ConnectionPool.shutdown(ConnectionPool.java:547):ContainerBackgroundProcessor[StandardEngine[Catalina]] - Connection #2 closed
[DEBUG] org.logicalcobwebs.proxool.ConnectionPool.removeProxyConnection(ConnectionPool.java:441):ContainerBackgroundProcessor[StandardEngine[Catalina]] - 000003 (00/00/00) - #0001 removed because of shutdown.
[DEBUG] org.logicalcobwebs.proxool.ConnectionPool.shutdown(ConnectionPool.java:547):ContainerBackgroundProcessor[StandardEngine[Catalina]] - Connection #1 closed
[INFO ] org.logicalcobwebs.proxool.ConnectionPool.shutdown(ConnectionPool.java:564):ContainerBackgroundProcessor[StandardEngine[Catalina]] - 'autumn' pool has been closed down by ContainerBackgroundProcessor[StandardEngine[Catalina]] in 6 milliseconds.
[DEBUG] org.logicalcobwebs.proxool.ShutdownHook.remove(ShutdownHook.java:41):ContainerBackgroundProcessor[StandardEngine[Catalina]] - Removed shutdownHook
[INFO ] org.logicalcobwebs.proxool.PrototyperController.shutdown(PrototyperController.java:100):ContainerBackgroundProcessor[StandardEngine[Catalina]] - Stopping Prototyper thread
[INFO ] org.logicalcobwebs.proxool.HouseKeeperController.shutdown(HouseKeeperController.java:107):ContainerBackgroundProcessor[StandardEngine[Catalina]] - Stopping HouseKeeper thread

排除了 poxool 导致 数据库连接泄露的问题。

proxool 连接池警告分析:appears to have started a thread named [HouseKeeper] but has failed to stop it的更多相关文章

  1. 警告: The web application [ROOT] appears to have started a thread named [Thread-48] but has failed to stop it. This is very likely to create a memory leak. Stack trace of thread:

    1. 问题描述 tomcat跑web项目(其中依赖java项目) 出现大量上述警告 项目起不来 关键字 memory leak 内存泄漏 2. 解决方案 难道是程序写的有问题? 最终 将tomcat ...

  2. 严重:The web application [web01] appears to have started a thread named ...

    Tomcat报错 严重:The web application [web01] appears to have started a thread named [PooledThread-1] but ...

  3. paip.proxool连接池 :Attempt to refer to a unregistered pool by its alias 'xx'

    paip.proxool连接池 :Attempt to refer to a unregistered pool by its alias 'xx' 作者Attilax  艾龙,  EMAIL:146 ...

  4. 使用proxool 连接池:No suitable driver found for proxool

    使用proxool连接池时:报错误No suitable driver found for proxool.shide的原因: ①.WEB-INF目录下的lib中没有proxool连接池jar驱动包. ...

  5. 使用proxool连接池配置教程

    proxool连接池的优点: 1.透明度:透明地将连接池添加到现有的JDBC驱动程序. 2.开源:我们的许可证允许您灵活地将其用于商业和其他开源产品. 3.标准:符合J2SE API,使您有信心开发标 ...

  6. MySql 8小时解决方案:proxool连接池

    最近做的项目用的mysql数据库,前天挂在服务器上,昨天早晨上班一来,同事就说API数据接口访问不了了,我马上mstsc登陆服务器看,报错了.马上重启tomcat,结果还能正常运行,当时没管,今天过来 ...

  7. Spring学习11-Spring使用proxool连接池 管理数据源

    Spring 一.Proxool连接池简介及其配置属性概述   Proxool是一种Java数据库连接池技术.是sourceforge下的一个开源项目,这个项目提供一个健壮.易用的连接池,最为关键的是 ...

  8. proxool 连接池

    今天配置proxool 连接池,发现可配置属性非常多,以前也只是用,没总结过,今天查了下网上的资料,总结一下 方便你我.其实网上很多英文资料都很全,网上很多人就是考翻译老外的文章赚些流量,其实也没啥意 ...

  9. proxool连接池参数解释

        数据库连接池概述: 数据库连接是一种关键的有限的昂贵的资源,这一点在多用户的网页应用程序中体现得尤为突出.对数据库连接的管理能显著影响到整个 应用程序的伸缩性和健壮性,影响到程序的性能指标.数 ...

随机推荐

  1. mysql,命令导入\导出表结构或数据

    在命令行下mysql的数据导出有个很好用命令mysqldump,它的参数有一大把,可以这样查看: mysqldump 最常用的: mysqldump -uroot -pmysql databasefo ...

  2. jquery.form.js不能解决连接超时(timeout)的解决方法

    最近在使用jquery.form.js提交包含文件的表单时,碰到了一个问题:当碰上网速较慢时,而我们又设置了timeout时,例如: var options = { timeout: 3000 //限 ...

  3. Spark集群 + Akka + Kafka + Scala 开发(3) : 开发一个Akka + Spark的应用

    前言 在Spark集群 + Akka + Kafka + Scala 开发(1) : 配置开发环境中,我们已经部署好了一个Spark的开发环境. 在Spark集群 + Akka + Kafka + S ...

  4. struts原理

    Struts是一个开源的web框架. 为什么会有struts? 因为我们对mvc理解的不同,可能造成不同公司写程序的时候,规范不统一,这样不利于程序的维护和扩展,所以我们有必要用一个统一的规范来开发项 ...

  5. Linux学习笔记14-权限基础

    权限基础 权限:操作系统限制对资源访问的机制,一般分为读.写.执行.每个文件都拥有特定权限,通过所属用户及所属组来限制哪些用户.组可以对特定文件进行什么样的操作. 每个进程都是以某个用户的身份运行,进 ...

  6. 以【猫叫、老鼠跑、主人醒】为例子,使用 javascript 来实现 观察者模式 (有在线演示)

    “猫叫.老鼠跑.主人醒”是一个很古老的话题了,大家也都有各自的想法和解决方案.我也是看了很多,一开始的时候是相当的迷糊,这个怎么就是面试题了?考的是啥呀,和编程有关系吗?又是猫又是老鼠的,晕死了.后来 ...

  7. 太可爱了!CSS3 & SVG 制作的米老鼠钟表

    米老鼠是大家非常熟悉的迪斯尼动画形象.这是一个可爱的效果,结合 CSS & SVG 图形实现的米老鼠钟表效果.Web 技术让很多生活中的事物都能搬到网上去,后面的推荐阅读也有很多的效果,感兴趣 ...

  8. 移动端-js触摸事件

    开发者工具 在移动开发中,一种较为容易的做法是,先在桌面上开始原型设计,然后再在打算要支持的设备上处理移动特有的部分.多点触摸正是难以在PC上进行测试的那些功能之一,因为大部分的PC都没有触摸输入. ...

  9. 认识基本的mfc控件

    几乎可以在每个windows程序中都看到按钮.复选框.文本框以及下拉列表等等,这些都是控件.而且很多常用的控件已经内置到操作系统当中了,在Visual C++中,这些常用控件已经简答到能用“拖放”这种 ...

  10. web页面直接跳转至其他页面

    <script type="text/javascript">window.location.herf="../../XXXXX.aspx";< ...