[技巧篇]14.据说SSH框架需要的监听器,IntrospectorCleanupListener
开发这么久,我也没有使用过IntrospectorCleanupListener监听器,今天偶尔看到一篇文章,虽然没有怎么读懂,也不太理解,但是好像给官方提供一些解释!给自己留一个备注,多点东西因为没有什么问题吧!
我想应该对整个程序没有太大的影响,在部署描述符web.xml中添加如下的监听器
<listener>
<listener-class>
org.springframework.web.util.IntrospectorCleanupListener
</listener-class>
</listener>
可能新的版本中没有这个问题吧,也许吧,自己没有遇到这样的问题!
spring的说明如下:
Listener that flushes the JDK's JavaBeans Introspector cache on web app shutdown. Register this listener in your web.xml to guarantee proper release of the web application class loader and its loaded classes.
If the JavaBeans Introspector has been used to analyze application classes, the system-level Introspector cache will hold a hard reference to those classes. Consequently, those classes and the web application class loader will not be garbage-collected on web app shutdown! This listener performs proper cleanup, to allow for garbage collection to take effect.
Unfortunately, the only way to clean up the Introspector is to flush the entire cache, as there is no way to specifically determine the application's classes referenced there. This will remove cached introspection results for all other applications in the server too.
Note that this listener is not necessary when using Spring's beans infrastructure within the application, as Spring's own introspection results cache will immediately flush an analyzed class from the JavaBeans Introspector cache and only hold a cache within the application's own ClassLoader. Although Spring itself does not create JDK Introspector leaks, note that this listener should nevertheless be used in scenarios where the Spring framework classes themselves reside in a 'common' ClassLoader (such as the system ClassLoader). In such a scenario, this listener will properly clean up Spring's introspection cache.
Application classes hardly ever need to use the JavaBeans Introspector directly, so are normally not the cause of Introspector resource leaks. Rather, many libraries and frameworks do not clean up the Introspector: e.g. Struts and Quartz.
Note that a single such Introspector leak will cause the entire web app class loader to not get garbage collected! This has the consequence that you will see all the application's static class resources (like singletons) around after web app shutdown, which is not the fault of those classes!
This listener should be registered as the first one in web.xml, before any application listeners such as Spring's ContextLoaderListener. This allows the listener to take full effect at the right time of the lifecycle.
翻译如下
其中JavaBeans Introspector是一个类,位置在Java.bean.Introspector,这个类的用途是发现java类是否符合javaBean规范,也就是这个类是不是javabean。具体用法可以参照jdk文档;
上面的意思就是,如果有的框架或者程序用到了JavaBeans Introspector了,那么就启用了一个系统级别的缓存,这个缓存会存放一些曾加载并分析过的javabean的引用,当web服务器关闭的时候,由于这个缓存中存放着这些javabean的引用,所以垃圾回收器不能对web容器中的javaBean对象进行回收,导致内存越来越大。
spring提供的org.springframework.web.util.IntrospectorCleanupListener就解决了这个问题,他会在web服务器停止的时候,清理一下这个Introspector缓存。使那些javabean能被垃圾回收器正确回收。
spring不会出现这种问题,因为spring在加载并分析完一个类之后会马上刷新JavaBeans Introspector缓存,这样就保证了spring不会出现这种内存泄漏的问题。
但是有很多程序和框架在使用了JavaBeans Introspector之后,都没有进行清理工作,比如quartz、struts;解决办法很简单,就是上面的那个配置。
请各位看看公司使用Spring的整合中是否有类似的代码,我这里不敢确认,也不把握,拜托了!给一个准确的答案,我还是感觉新的版本没有这个问题!
各位早安,有的时候不知道对错,总是坚持对吗?精进,忍耐,诚实,还有用吗?
[技巧篇]14.据说SSH框架需要的监听器,IntrospectorCleanupListener的更多相关文章
- SSH框架构建微信公众帐号服务器小技巧
SSH框架构建微信公众帐号服务器小技巧 熟悉struts2和servlet的同学应该清楚,struts2的方法多样性弥补了servlet单一的doGet 和doPost方法.如果自己的公众账号服务器是 ...
- javaWeb项目(SSH框架+AJAX+百度地图API+Oracle数据库+MyEclipse+Tomcat)之一 基础Struts框架搭建篇
即将开始着手写这个项目,所以希望通过这篇博客来记录自己学习的过程 今天开学第一天,就上了软件工程实践课,自己也开始着手做这个大作业了.首先我的项目名称叫做智能班车管理系统. 项目的概况: 该软件产品是 ...
- SSH框架搭建详细图文教程(转)
这篇文章看的我醍醐灌顶的感觉,比之前本科时候学习的SSH架构 要清晰数倍 非常感觉这篇博主的文章 文章链接为:http://blog.sina.com.cn/s/blog_a6a6b3cd01017 ...
- 《手把手教你》系列技巧篇(四十四)-java+ selenium自动化测试-处理https 安全问题或者非信任站点-下篇(详解教程)
1.简介 这一篇宏哥主要介绍webdriver在IE.Chrome和Firefox三个浏览器上处理不信任证书的情况,我们知道,有些网站打开是弹窗,SSL证书不可信任,但是你可以点击高级选项,继续打 ...
- 初识SSH框架
想了解SSH的工作原理吗?还不快快来看我的新文章----ssh框架的工作原理 也许你还不知道SSH存在的意义,但只是因为在没点开这篇文章之前的事了. SSH由Strut2,Spring,Hiberna ...
- SSH框架简化(struts2+spring+hibernate)
目的: 通过对ssh框架有了基础性的学习,本文主要是使用注解的方式来简化ssh框架的代码编写. 注意事项: 1.运行环境:Windows 8-64位,Eclipse(开发工具),jdk1.8.0_91 ...
- SSH框架的简单示例(执行流程)
本文转自一篇博文,感觉通俗易懂,适用于初学j2ee者,与大家一起分享 (一)struts框架部分 1.打开Myeclipse,创建一个web project,项目名称为TestSSH. 2.在web的 ...
- FastReport 使用技巧篇
使用技巧篇 1.FastReport中如果访问报表中的对象? 可以使用FindObject方法. TfrxMemoView(frxReport1.FindObject('memo ...
- SSH框架之一详解maven搭建多模块项目
闲来无事,思量着自己搭建一个ssh框架,一来回顾熟悉一下ssh的内容,hibernate还就没用过了,生疏了都.二来整合一下,将其他掌握的和正在学习的框架核技术糅合到一起,就当是做一个demo练手了. ...
随机推荐
- Python 学习笔记之——用 sklearn 对数据进行预处理
1. 标准化 标准化是为了让数据服从一个零均值和单位方差的标准正态分布.也即针对一个均值为 \(mean\) 标准差为 \(std\) 的向量 \(X\) 中的每个值 \(x\),有 \(x_{sca ...
- Java实验二实验报告:java面向对象程序设计
java实验二实验报告 实验内容 1. 初步掌握单元测试和TDD 2. 理解并掌握面向对象三要素:封装.继承.多态 3. 初步掌握UML建模 4. 熟悉S.O.L.I.D原则 5. 了解设计模式 实验 ...
- 【IdentityServer4文档】- 支持协议
IdentityServer 实现了以下协议: OpenID Connect OpenID Connect Core 1.0 (spec) OpenID Connect Discovery 1.0 ( ...
- ACM 第十五天
计算几何基础 练习题 C - Wasted Time Mr. Scrooge, a very busy man, decided to count the time he wastes on all ...
- 【week7】psp
本周psp 项目 内容 开始时间 结束时间 中断时间 净时间 2016/10/31 技术学习 看向数据库传入数据的代码 18:00 21:00 45 135 psp记录 将psp记录进电脑 21:20 ...
- return 返回字符串
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Cons ...
- Events-事件-红绿灯
Event: 用于线程之间状态的同步.对全局变量不断地做修改. Event=threading.Event() #生成1个event的对象 Event.wait() #等着设定全局变量.检测标志位是 ...
- Oracle 验证A表的2个字段组合不在B表2个字段组合里的数据
select id, name from TAB_A t where not exists (select 1 from TAB_B t1 where t.id = t1.id and t.name ...
- STL使用记录
1,map 对map实在不熟...赶紧记录一下用法吧. 后来再发现新的用法再补充吧 定义: map<int, int> m; 其中的int可以为自定义的任何类型. m[key值类型的变量] ...
- BZOJ1068:[SCOI2007]压缩——题解
http://www.lydsy.com/JudgeOnline/problem.php?id=1068 Description 给一个由小写字母组成的字符串,我们可以用一种简单的方法来压缩其中的重复 ...