04、IntrospectorCleanupListener



解決Spring整合其他框架和類庫(非Spring託管的Bean,如Struts、quartz)產生的單個內部查看泄露使得整個web應用的類加載器不能進行垃圾回收。

類路徑:org.springframework.web.util.IntrospectorCleanupListener;

解決問題:處理由JavaBean Introspector使用而引起的緩衝泄露, 它是一個在web應用關閉時清除JavaBean Introspector的監聽器;

使用方法:在web.xml中註冊這個listener可以保證在web應用關閉的時候釋放掉與這個web應用相關的class loader和由它管理的類;

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

源代碼如下:
package  org.springframework.web.util;   
import  java.beans.Introspector;   
import  javax.servlet.ServletContextEvent;   
import  javax.servlet.ServletContextListener;   
  
public   class  IntrospectorCleanupListener  implements  ServletContextListener   {   
     public   void  contextInitialized(ServletContextEvent event)   {   
    }    
    
      public   void  contextDestroyed(ServletContextEvent event)   {   
        Introspector.flushCaches();   
    }    
}

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章