`
paladin1988
  • 浏览: 331983 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

【转】在web.xml中注册IntrospectorCleanupListener监听器以解决struts等框架可能产生的内存泄露问题

 
阅读更多

 

原文链接:http://blog.csdn.net/yakoo5/article/details/8240925

 

增加方式如下:

 

 

    <listener>  
        <listener-class>  
            org.springframework.web.util.IntrospectorCleanupListener  
        </listener-class>  
    </listener> 

 

 

org.springframework.web.util.IntrospectorCleanupListener源代码中对其的解释如下:

 

        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.

 

        在Web应用程序关闭时IntrospectorCleanupListener将会刷新JDK的JavaBeans的Introspector缓存。在 你的web.xml中注册这个listener来确保Web应用程序的类加载器以及其加载的类正确的释放资源。

 

 

        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.      

 

       如果JavaBeans的Introspector已被用来分析应用程序类,系统级的Introspector缓存将持有这些类的一 个硬引用。因此,这些类和Web应用程序的类加载器在Web应用程序关闭时将不会被垃圾收集器回收!而 IntrospectorCleanupListener则会对其进行适当的清理,已使其能够被垃圾收集器回收。

 

 

       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.

 

       不幸的是,唯一能够清理Introspector的方法是刷新整个Introspector缓存,没有其他办法来确切指定应用程序所引用的类。这将删除所有其他应用程序在服务器的缓存的Introspector结果。

 

 

       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.

 

       请注意,在使用Spring内部的bean机制时,不需要使用此监听器,因为Spring自己的introspection results cache将会立即刷新被分析过的JavaBeans Introspector cache,而仅仅会在应用程序自己的ClassLoader里面持有一个cache。虽然Spring本身不产生泄漏,注意,即使在Spring框架的 类本身驻留在一个“共同”类加载器(如系统的ClassLoader)的情况下,也仍然应该使用使用 IntrospectorCleanupListener。在这种情况下,这个IntrospectorCleanupListener将会妥善清理 Spring的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.

 

       应用程序类,几乎不需要直接使用JavaBeans Introspector,所以,通常都不是Introspector resource造成内存泄露。相反,许多库和框架,不清理Introspector,例如: Struts和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!

 

        需要注意的是一个简单Introspector泄漏将会导致整个Web应用程序的类加载器不会被回收!这样做的结果,将会是在web应用程序关闭时,该应 用程序所有的静态类资源(比如:单实例对象)都没有得到释放。而导致内存泄露的根本原因其实并不是这些未被回收的类!

 

 

       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. 

 

       IntrospectorCleanupListener应该注册为web.xml中的第一个Listener,在任何其他 Listener之前注册,比如在Spring's ContextLoaderListener注册之前,才能确保IntrospectorCleanupListener在Web应用的生命周期适当时机 生效。

分享到:
评论

相关推荐

    spring在web.xml中和在struts中的不同配置..pdf

    在Java Web开发中,Spring和Struts是两个非常流行的框架,它们在构建应用程序时有着不同的配置方式。在本文中,我们将探讨Spring在`web.xml`中的配置与在Struts中的配置差异,以及这两种配置方式背后的基本原理。 ...

    在web.xml中配置action或.do

    随着技术的发展,虽然现代Web框架如Spring MVC等提供了更为灵活和强大的机制来管理这些操作,但了解如何在`web.xml`中配置action仍然是非常有用的,尤其是在维护旧项目或者特定场景下。 #### 三、配置步骤详解 ...

    struts.xml和applicationContext.xml、web.xml的配置

    在Java Web开发中,`struts.xml`, `applicationContext.xml` 和 `web.xml` 是三个至关重要的配置文件,它们各自负责不同的职责,并协同工作来构建一个完整的应用框架。以下是关于这三个配置文件的详细说明。 首先,...

    struts1中web.xml配置详解

    在 web.xml 文件中,需要配置 Struts 的 ActionServlet,以便于 Struts 框架能够正确地工作。ActionServlet 是 Struts 框架中的核心组件,它负责处理来自客户端的请求和响应。配置 ActionServlet 需要在 `&lt;servlet&gt;`...

    struts2.5 web.xml配置

    在探讨Struts2.5中的`web.xml`配置时,我们首先需要理解`web.xml`在Java Web应用中的角色以及它如何与Struts框架交互。`web.xml`是Java Web应用的核心配置文件之一,用于定义应用程序级别的配置信息,如过滤器、监听...

    SSH和SSI等框架常用基础配置web.xml

    ### SSH和SSI等框架常用基础配置web.xml 在Java Web应用开发中,`web.xml`是部署描述符的核心部分,用于定义与Web应用程序相关的配置信息。对于使用SSH(Struts + Spring + Hibernate)和SSI(Struts + Spring + ...

    struts.xml文件详解.doc

    Struts.xml文件是Apache Struts 2框架的核心配置文件,它用于定义应用程序的行为、Action映射、结果页面、拦截器等关键组件。在深入讲解struts.xml之前,我们先来了解与之相关的struts.properties文件。 struts....

    Web.xml中配置Struts[参考].pdf

    Struts框架在Web.xml中的配置 Struts框架是Java EE中的一种基于MVC模式的Web应用程序框架,它提供了一个灵活的架构,可以快速开发Web应用程序。在Struts框架中,配置文件Web.xml是核心配置文件之一,本文将详细介绍...

    web.xml_(详解).docx

    `web.xml`是Web应用程序的部署描述符,它是Java EE规范中定义的一个XML文件,用于配置Web应用程序的各种元素,如Servlet、过滤器、监听器等。在这个文件中,我们可以设置应用程序的全局行为,比如初始化参数、错误...

    flex4,struts2.3兼容配置web.xml

    flex4,struts2.3兼容配置web.xml

    sruts2.0 web.xml 配置文件

    `web.xml`配置文件在Struts2中扮演着至关重要的角色,它是整个应用的部署描述符,定义了应用程序的入口点、过滤器、Servlet以及其他Web组件的配置信息。在这里,我们将深入探讨`web.xml`配置文件在Struts2中的应用...

    Web.xml中配置Struts[文].pdf

    7. Filter配置:虽然不是直接在`web.xml`中配置Struts,但Struts2引入了Filter的概念,`struts2-core.jar`包含了一个名为`StrutsPrepareAndExecuteFilter`的Filter,用来处理所有的HTTP请求,替代了Struts1中的...

    Struts2手动搭建所有的jar包及相应的struts.xml和web.xml

    Struts2是一款强大的Java Web框架,它为开发者提供了一种优雅的方式来实现MVC(Model-View-Controller)架构,使得应用程序的开发更为简洁、高效。本教程将详细讲解如何手动搭建一个完整的Struts2环境,包括引入所有...

    Struts2.5版本struts.xml与web.xml配置的更改方法

    在Struts2框架中,配置文件`struts.xml`和`web.xml`是核心部分,它们定义了应用程序的行为和路由规则。随着版本的更新,配置方式也会有所改变。以下是Struts2.5版本中`struts.xml`和`web.xml`配置的更改方法: **1....

    org.springframework.web.struts-sources-3.0.4.RELEASE.jar

    在Java Web开发领域,Spring框架以其强大的依赖注入和面向切面编程能力,而Struts则以其优秀的MVC架构模式,共同构建了众多企业级应用的基础。当这两者结合时,可以形成一个强大且灵活的开发环境。本文将详细解析`...

    struts2版本 2.1.6 必须的jar包 和 web.xml 文件的修改

    在Struts2中,`web.xml`是应用的部署描述符,它定义了初始化参数、过滤器、监听器和Servlet等关键元素。以下是你需要关注的部分: 1. **StrutsPrepareAndExecuteFilter** - 配置Struts2的过滤器,负责拦截所有HTTP...

    struts、applicationContext配置文件移动后web.xml配置示例

    使用myeclipse8.5搭建SSH后,将struts.xml和applicationContext.xml移动到别的地方,示例中为webroot下的config文件夹中,web.xml中需要做的修改示例。其中对于返回上一层方式不同的myeclipse可能不同,如有的用../...

    web.xml加入taglib报错

    在Java Web开发中,`web.xml`是应用的部署描述符,它定义了Servlet、过滤器、监听器等组件的配置信息。当我们尝试在`web.xml`中添加`taglib`引用时,可能会遇到一些报错。这篇博客讨论的是如何解决在`web.xml`中配置...

    SSH三大框架整合 struts2(使用xml配置)+hibernate(使用xml配置)+spring(使用xml配置)

    SSH是Java Web开发中的三个重要框架,分别是Struts2、Hibernate和Spring,它们共同构建了一个强大的MVC(Model-View-Controller)架构。本项目整合了这三个框架,并使用XML配置来管理各个组件,实现了基本的CRUD...

    struts2所需的jar+struct.xml+web.xml+jdbc.java

    在Struts2中,你需要在`web.xml`中配置过滤器(`&lt;filter&gt;`和`&lt;filter-mapping&gt;`),如`StrutsPrepareAndExecuteFilter`,使得Struts2能拦截所有请求并进行处理。 4. **jdbc.java**: - 这通常是指Java数据库连接...

Global site tag (gtag.js) - Google Analytics