mjiderhamn / classloader-leak-prevention

ClassLoader leak prevention / protection
http://java.jiderhamn.se/2012/03/04/classloader-leaks-vi-this-means-war-leak-prevention-library/
Apache License 2.0
358 stars 88 forks source link

log4j2 compatibility #48

Open mjiderhamn opened 8 years ago

mjiderhamn commented 8 years ago

See #40. @dhuygu :

If I dont create a new class that extends ClassLoaderLeakPreventor an exception is thrown because of log4j2 and lmax disruptor library. So I extended and added below code not to get exception: if (LogManager.getContext() != null) { try { AsyncLoggerContext logContext = (AsyncLoggerContext) LogManager.getContext(); logContext.stop(); } catch (Exception e) { }

log4j2 version is 2.3. If ı use log4j 2.5 Log4jThread classes stay alive after undeployment.

mjiderhamn commented 8 years ago

@dhuygu

My log4j2 version is 2.3 (I want to upgrade 2.5 but there are some Log4JThread leaks in this version ) I am using log4j2 asynchronus loggers. Asynchronous Loggers internally use the lmax disruptor. I added log4j2.component.properties file to say log4j2 to use AsyncLoggerContextSelector: Log4jContextSelector=org.apache.logging.log4j.core.async.AsyncLoggerContextSelector. log4j2.xml file all my loggers are AsyncLogger and appenders are RollingRandomAccessFile. If you need additional data please ask.

mjiderhamn commented 8 years ago

Seems to be avoided by using a ShutdownCallbackRegistry as per http://stackoverflow.com/a/28835409.

See test case in commit https://github.com/mjiderhamn/classloader-leak-prevention/commit/a2783a09ebb64a1ccc5804f94507ca52f0e88bb6

Still need to look into version 2.5