`
deejay
  • 浏览: 144321 次
  • 性别: Icon_minigender_1
  • 来自: 成都
社区版块
存档分类
最新评论

ssh中需要增加IntrospectorCleanupListener监听器

    博客分类:
  • ssh2
阅读更多
增加方式如下:
<!--<br /> <br /> Code highlighting produced by Actipro CodeHighlighter (freeware)<br /> http://www.CodeHighlighter.com/<br /> <br /> -->    <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;解决办法很简单,就是上面的那个配置。

分享到:
评论

相关推荐

    SSH整合需要的jar包

    - spring-web:提供Web相关的支持,如Servlet监听器和过滤器。 2. **Struts2框架**: - struts2-core:Struts2的核心库,包括Action、结果类型、拦截器等。 - struts2-convention:提供约定优于配置的功能。 - ...

    SSH需要的jar,ssh完整jar

    在Java项目中使用这些SSH相关的jar文件时,通常需要将它们添加到项目的类路径中,以便编译和运行时能够访问其中的类。在Maven或Gradle这样的构建工具中,可以通过指定依赖来自动管理这些jar文件。 例如,如果你的...

    ssh最新框架搭建,加入拦截器

    3. 配置Web应用的web.xml文件,设置过滤器和监听器。 4. 创建并配置Struts2的核心配置文件struts.xml,定义Action、结果类型和拦截器。 5. 实现业务逻辑,包括Action类、Service接口和实现、DAO接口和实现。 6. 配置...

    ssh框架整合需要的 jar包

    - spring-web.jar:处理Web相关的功能,如Servlet监听器、HTTP请求解析等。 - spring-webmvc.jar:Spring的MVC实现,用于处理Web请求和响应。 - spring-aop.jar:支持面向切面编程,提供声明式事务管理等功能。 ...

    ssh框架 ssh框架 ssh框架 ssh框架 ssh框架 ssh框架 ssh框架 ssh框架

    ssh ssh shhs ssh ssh shhs ssh ssh shhs ssh ssh shhs ssh ssh shhs ssh ssh shhs ssh ssh shhs ssh ssh shhs ssh ssh shhs ssh ssh shhs ssh ssh shhs ssh ssh shhs ssh ssh shhs ssh ssh shhs ssh ssh shhs ssh ...

    Win 10 ODBC SSH协议远程连接MySQL 3306.docx

    在本文中,我们将探讨如何使用 Win 10 自带的 OPENSSH 通过 SSH 协议远程连接 MySQL 服务器, 并使用 ODBC 连接到远程 MySQL 服务器。 SSH 协议 SSH(Secure Shell)是一种安全的网络协议,用于远程登录和管理网络...

    SSH2网页增加、删除、改、查、上传下载、分页功能

    1. **增加(Create)**:在Web应用中,增加功能通常指的是创建新的数据记录。SSH2框架可能结合了Model-View-Controller(MVC)设计模式,使得开发者可以方便地创建表单,处理用户输入,并通过后端服务将新数据存储到...

    Centos7增加或修改SSH端口号的方法.doc

    首先,需要切换到root用户,然后使用vim编辑器打开/etc/ssh/sshd_config文件。找到“#Port 22”这行,复制该行到下一行,然后把“#”号注释去掉即可,修改为一个随机端口。例如,修改为Port 63852。 关于SSH其他...

    ssh整合需要的jar包

    - spring-web.jar:Web相关的支持,如Servlet监听器和过滤器。 - spring-webmvc.jar:Spring MVC组件,负责处理HTTP请求。 - spring-aop.jar:面向切面编程的实现。 - spring-orm.jar:数据库集成,包括...

    SSH整合需要的jar包整理

    此外,还需设置web.xml以配置过滤器、监听器等,确保请求能被正确处理。 整合SSH的过程中,理解每个框架的核心概念和它们之间的交互至关重要,这将有助于编写高效且易于维护的代码。通过熟练掌握这些知识,开发者...

    SSH.NET-develop.zip_SSH.net_VI1Q_ssh

    为了深入理解SSH.NET,开发者需要熟悉.NET框架、C#编程语言以及SSH协议本身。同时,阅读和分析压缩包中的源代码、文档和示例将有助于快速掌握SSH.NET的用法,从而在自己的项目中有效地应用SSH安全通信。

    使用ssh、scp不需要密码

    如果将公钥复制到要访问的机器上,并保存到 ~/.ssh/authorized_keys 文件中,那么可以不需要密码使用 ssh 和 scp 进行登陆和文件传输。 使用 Expect 实现密钥对生成 Expect 是一个自动化工具,可以用于自动生成...

    ssh集成 ssh集成

    SSH(Secure Shell)是一种网络协议,用于在不安全的网络上提供安全的远程登录和其他服务。SSH集成通常指的是将SSH功能与其他系统或工具...无论是开发人员还是系统管理员,都需要熟练运用SSH集成来优化日常工作流程。

    sshshell.zip

    通过SSH,用户可以执行命令、传输文件,而不用担心数据被窃听或篡改。 首先,我们要理解SSH的工作原理。它使用公钥加密技术来验证服务器身份,并为通信双方创建一个加密的隧道,确保数据传输的安全性。SSH的主要...

    SSH实现查找和增加功能.rar

    实践中,开发者需要配置Struts2的拦截器、过滤器,以及Spring的事务管理,以确保功能的正确性和性能。同时,为了实现查找功能,开发者需要熟练掌握HQL或SQL查询,而增加功能则涉及到对象的创建、持久化以及事务提交...

    SSH中文API帮助文档

    SSH中文帮助文档 ...觉得很实用.拿出来.给大家分享..希望对大家有用

    最新SSH所需jar包

    SSH(Struts2 + Spring + Hibernate)是一种经典的Java Web开发框架组合,用于构建高效、可扩展的企业级应用...在实际开发中,还需要关注框架的版本兼容性,及时更新修复安全漏洞的版本,以保证应用的安全性和稳定性。

    ssh开发所需基本jar包

    - `spring-web.jar`: 用于处理Web相关的功能,如Servlet监听器和过滤器。 - `spring-webmvc.jar`: 提供了Spring的MVC框架,与Struts2类似但提供了更灵活的配置。 - `spring-aop.jar`: 支持AOP编程,包括切点、...

    ssh升级所需要的rpm包

    在Linux系统中,SSH(Secure Shell)是一种网络协议,用于安全地远程登录到服务器,执行命令,传输文件等。SSH的升级是确保系统安全的重要环节,因为随着时间的推移,旧版本可能会出现安全漏洞,而新版本则会修复...

Global site tag (gtag.js) - Google Analytics