以前的項(xiàng)目用的是struts1,運(yùn)行得好好的,現(xiàn)在改用struts2后,發(fā)現(xiàn)運(yùn)行不到一天tomcat就出現(xiàn)內(nèi)存溢出的錯(cuò)誤。使用jProfiler分析一下,發(fā)現(xiàn)tomcat啟動(dòng)后使用的內(nèi)存就一路飆升,而且放在action里面的類根本沒(méi)有釋放掉,應(yīng)該是struts出現(xiàn)了問(wèn)題,查一下struts的配置,原來(lái)沒(méi)有配ActionContextCleanUp,在web.xml中加入
<filter>
<filter-name>struts-cleanup</filter-name>
<filter-class>
org.apache.struts2.dispatcher.ActionContextCleanUp
</filter-class>
</filter>
<filter-mapping>
<filter-name>struts-cleanup</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
再次用jprofiler進(jìn)行分析,果然好了。
<filter>
<filter-name>struts-cleanup</filter-name>
<filter-class>
org.apache.struts2.dispatcher.ActionContextCleanUp
</filter-class>
</filter>
<filter-mapping>
<filter-name>struts-cleanup</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
再次用jprofiler進(jìn)行分析,果然好了。