测试服务器上直接修改properties文件导致OOM的问题

来源:互联网 发布:linux 查看数据包 编辑:程序博客网 时间:2024/06/09 16:34
场景:测试服务器上,在未停止tomcat的情况下直接修改了配置文件(properties文件),稍后再有请求进来时(该请求会使用到properties文件中的属性),引发了OOMtomcat7.0.50配置文件:conf/server.xml中:<Context docBase="advertise-war" path="/advertise-war" reloadable="true" />path:访问该Web应用的URL入口reloadable:tomcat在运行时会监控 WEB-INF/classes 和 WEB-INF/lib目录下的class文件,如果监测到有class文件被更新的,tomcat会自动重新加载(先卸载,再部署)Web应用。分析:1)在卸载的过程中,(大概是由于文件被修改后)程序可能出错,导致原来的web应用卸载失败,从而导致原来的web应用仍然存在于Tomcat的缓存之中。2)虽然卸载失败,但是tomcat仍然会部署修改后的web应用。3)从而导致:tomcat在重新部署web应用时,由于无法删除已有的缓存,故可能会出现内存溢出的异常。建议:1)将reloadable属性设为false。2)将需要经常修改的配置文件(properties文件等)的配置信息持久化到数据库中。即:获取配置信息的策略由 配置文件的形式 改为 从数据库中获取(如果频繁使用,则放到缓存中)。
之后进行本地测试时,部分日志的截取:


注:虽然没有报OOM,但是从日志可以推断出:如果重启前,正在执行的线程比较多的话,则在重启的过程中很可能报OOM。


 7:39:42 下午 org.apache.catalina.core.StandardContext reload
信息: Reloading Context with name [/landpage-***-war] has started
 7:39:42 下午 org.apache.catalina.core.StandardWrapper unload
信息: Waiting for 1 instance(s) to be deallocated for Servlet [advertise-landpage]
 7:39:43 下午 org.apache.catalina.core.ApplicationContext log
信息: Destroying Spring FrameworkServlet 'advertise-landpage'
 7:39:43 下午 org.apache.catalina.core.ApplicationContext log
信息: Closing Spring root WebApplicationContext
 7:39:43 下午 org.apache.catalina.loader.WebappClassLoaderBase clearReferencesJdbc
警告: The web application [landpage-***-war] registered the JDBC driver [com.mysql.jdbc.Driver] but failed to unregister it when the web application was stopped. To prevent a memory leak, the JDBC Driver has been forcibly unregistered.
 7:39:43 下午 org.apache.catalina.loader.WebappClassLoaderBase clearReferencesThreads
警告: The web application [landpage-***-war] appears to have started a thread named [Abandoned connection cleanup thread] but has failed to stop it. This is very likely to create a memory leak. Stack trace of thread:
java.lang.Object.wait(Native Method)
java.lang.ref.ReferenceQueue.remove(Unknown Source)
com.mysql.jdbc.AbandonedConnectionCleanupThread.run(AbandonedConnectionCleanupThread.java:40)
 7:39:43 下午 org.apache.catalina.loader.WebappClassLoaderBase clearReferencesThreads
警告: The web application [landpage-***-war] appears to have started a thread named [Timer-0] but has failed to stop it. This is very likely to create a memory leak. Stack trace of thread:
java.lang.Object.wait(Native Method)
java.util.TimerThread.mainLoop(Unknown Source)
java.util.TimerThread.run(Unknown Source)
 7:39:43 下午 org.apache.catalina.loader.WebappClassLoaderBase clearReferencesThreads
警告: The web application [landpage-***-war] appears to have started a thread named [MySQL Statement Cancellation Timer] but has failed to stop it. This is very likely to create a memory leak. Stack trace of thread:
java.lang.Object.wait(Native Method)
java.lang.Object.wait(Unknown Source)
java.util.TimerThread.mainLoop(Unknown Source)
java.util.TimerThread.run(Unknown Source)
 7:39:43 下午 org.apache.catalina.loader.WebappClassLoaderBase checkThreadLocalMapForLeaks
严重: The web application [landpage-***-war] created a ThreadLocal with key of type [org.springframework.core.NamedThreadLocal] (value [Locale context]) and a value of type [org.springframework.context.i18n.SimpleLocaleContext] (value [zh_CN]) but failed to remove it when the web application was stopped. Threads are going to be renewed over time to try and avoid a probable memory leak.
 7:39:43 下午 org.apache.catalina.loader.WebappClassLoaderBase checkThreadLocalMapForLeaks
严重: The web application [landpage-***-war] created a ThreadLocal with key of type [org.springframework.core.NamedThreadLocal] (value [Request attributes]) and a value of type [org.springframework.web.context.request.ServletRequestAttributes] (value [org.apache.catalina.connector.Request@7c2addba]) but failed to remove it when the web application was stopped. Threads are going to be renewed over time to try and avoid a probable memory leak.
 7:39:46 下午 org.apache.jasper.servlet.TldScanner scanJars
信息: At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time.
 7:39:46 下午 org.apache.catalina.core.ApplicationContext log
信息: No Spring WebApplicationInitializer types detected on classpath

 7:39:46 下午 org.apache.catalina.core.ApplicationContext log
信息: Initializing Spring root WebApplicationContext

 7:39:49 下午 org.apache.catalina.core.ApplicationContext log
信息: Initializing Spring FrameworkServlet 'advertise-landpage'

 7:39:50 下午 org.apache.catalina.core.StandardContext reload
信息: Reloading Context with name [/landpage-***-war] is completed




原创粉丝点击