简体   繁体   中英

Tomcat memory leak issue on log4j thread

I'm facing issue of memory leak in log4j v1.How to resolve this memory leak issue. This method is periodically check log4j.properties file update in my class.

PropertyConfigutaror.configureAndWatch(time_ms);

But during shutdown tomcat memory leak issue comes. Logs are below:

06-Oct-2016 15:13:55.973 WARNING [localhost-startStop-2] org.apache.catalina.loader.WebappClassLoaderBase.clearReferencesThreads The web application [myapp] appears to have started a thread named [Thread-10] but has failed to stop it. This is very likely to create a memory leak. Stack trace of thread:

java.lang.Thread.sleep(Native Method) org.apache.log4j.helpers.FileWatchdog.run(FileWatchdog.java:103)

Thanks in advance

Is there a way to get log4j to automatically reload a configuration file if it changes?

Yes. Both the DOMConfigurator and the PropertyConfigurator support automatic reloading through the configureAndWatch method. See the API documentation for more details.

Because the configureAndWatch launches a separate wathdog thread, and because there is no way to stop this thread in log4j 1.2, the configureAndWatch method is unsafe for use in J2EE envrironments where applications are recycled. (1)

The second statement is also true for a not full-blown app server like Tomcat.

I would suggest to update to log4j 2 if you want to reload your configuration during runtime.

What's also possible is to write your own properties file reader and set the log configuration programmatically. For more information see Change Log4j properties at runtime .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM