博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Tomcat的ThreadLocalLeakPreventionListener工作原理
阅读量:4213 次
发布时间:2019-05-26

本文共 1155 字,大约阅读时间需要 3 分钟。

当context stop的时候,如果thread pool的thread没有正常停止的话,而且ThreadLocal中引用了webclassloader加载的对象,有很有可能造成内存泄露,一个解决办法就是杀掉所有的threadpool的线程。Tomcat的ThreadLocalLeakPreventionListener就是这样一个原理 Engine engine = (Engine) context.getParent().getParent();

Service service = engine.getService();        Connector[] connectors = service.findConnectors();        if (connectors != null) {            for (Connector connector : connectors) {                ProtocolHandler handler = connector.getProtocolHandler();                Executor executor = null;                if (handler != null) {                    executor = handler.getExecutor();                }                if (executor instanceof ThreadPoolExecutor) {                    ThreadPoolExecutor threadPoolExecutor =                        (ThreadPoolExecutor) executor;                    threadPoolExecutor.contextStopping();                } else if (executor instanceof StandardThreadExecutor) {                    StandardThreadExecutor stdThreadExecutor =                        (StandardThreadExecutor) executor;                    stdThreadExecutor.contextStopping();                }            }        }    }
 

转载地址:http://nmdmi.baihongyu.com/

你可能感兴趣的文章
递归 理解
查看>>
欧几里德求最大公约数/最小公倍数
查看>>
hdoj 1016 素数环
查看>>
POJ 3617 字典序最小
查看>>
筛法求素数
查看>>
atoi/atof 字符串转Int/float
查看>>
数字字符串与int相互转化
查看>>
PAT 天梯赛 L1-025 A+B
查看>>
hdoj 1597 二分 下界(等差数列)
查看>>
二分查找
查看>>
hdoj 1180 搜索 + bfs + 优先队列
查看>>
hdoj 2141 二分 + 优化
查看>>
PAT 天梯赛 L1-027. 出租 (简单字符串处理)
查看>>
hdoj 1863 最小生成树(kruskal + 并查集)
查看>>
hdoj 1001 水题坑人 小心
查看>>
康拓展开
查看>>
二叉堆 删除 插入 调整 堆排序
查看>>
hdoj 1874 单源最短路径
查看>>
hdoj 2544 最短路径 dijkstra + 优先队列
查看>>
同余定理 + 快速幂
查看>>