Introduction to spring listener IntrospectorCleanupListener

Quoting an explanation about the IntrospectorCleanupListener:

During the server running process, Spring's non-stop running scheduled tasks and OpenSessionInViewFilter cause Tomcat to repeatedly load objects and generate memory leaks that may occur when the framework is used. IntrospectorCleanupListener is used as the corresponding solution.
Spring provides a listener named org.springframework.web.util.IntrospectorCleanupListener. It is mainly responsible for dealing with buffer leaks caused by the use of the JavaBeans Introspector.
It is described in Spring as follows:
It is a listener that clears the JavaBeans Introspector when the web application is closed. Registering this listener in web.xml ensures that the class loader related to the web application and the classes managed by it are released when the web application is closed. If you use JavaBeans Introspector to analyze classes in your application, references to those classes are kept in the Introspector buffer. As a result, these classes and the web application related class loaders are not garbage collected when your application closes. Unfortunately, The only way to clear the Introspector is to flush the entire buffer. This is because we can't tell which references belong to your application. So deleting the buffered Introspection will delete the Introspection of all applications on this computer.
It should be noted that Spring-managed beans do not need to use this listener. Because the buffer used by Spring's own Introspection is cleared from the JavaBeans Introspector buffer immediately after analyzing a class. The classes in the application never use the JavaBeans Introspector directly. So they generally do not lead to leaks of internal viewing resources. But some class libraries and frameworks tend to have this problem.
For example: Struts and Quartz. A single internal view leak can prevent the entire web application's classloader from being garbage collected. After the web application is closed, you will see all static class resources (such as singletons) for this application. The error is of course not caused by the class itself.

The usage is very simple, just add in web.xml:

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

Only know that the servlet standard does not allow thread management in the web container by itself, and the problem of quartz does exist.

For web containers, it is most taboo for applications to start threads privately and schedule threads on their own. A framework like Quartz that starts 10 threads by default for asynchronous job scheduling inside the web container is itself a very dangerous thing, and it is easy to cause The servlet thread resource cannot be recycled, so I always reject the use of quartz.

Another problem with quartz is that it does not support cluster. As a result, there is no way to cluster applications using quartz.

 

http://blog.sina.com.cn/s/blog_534f69a001013a20.html

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326425675&siteId=291194637