You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@logging.apache.org by rp...@apache.org on 2013/10/15 18:56:32 UTC
svn commit: r1532427 - in /logging/log4j/log4j2/trunk:
log4j-core/src/main/java/org/apache/logging/log4j/core/async/AsyncLoggerConfigHelper.java
src/changes/changes.xml
Author: rpopma
Date: Tue Oct 15 16:56:32 2013
New Revision: 1532427
URL: http://svn.apache.org/r1532427
Log:
LOG4J2-425 eliminated ThreadLocal from AsyncLoggerConfigHelper by using EventTranslatorTwoArg
Modified:
logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/async/AsyncLoggerConfigHelper.java
logging/log4j/log4j2/trunk/src/changes/changes.xml
Modified: logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/async/AsyncLoggerConfigHelper.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/async/AsyncLoggerConfigHelper.java?rev=1532427&r1=1532426&r2=1532427&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/async/AsyncLoggerConfigHelper.java (original)
+++ logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/async/AsyncLoggerConfigHelper.java Tue Oct 15 16:56:32 2013
@@ -27,7 +27,7 @@ import org.apache.logging.log4j.status.S
import com.lmax.disruptor.BlockingWaitStrategy;
import com.lmax.disruptor.EventFactory;
import com.lmax.disruptor.EventHandler;
-import com.lmax.disruptor.EventTranslator;
+import com.lmax.disruptor.EventTranslatorTwoArg;
import com.lmax.disruptor.ExceptionHandler;
import com.lmax.disruptor.RingBuffer;
import com.lmax.disruptor.Sequence;
@@ -84,16 +84,17 @@ class AsyncLoggerConfigHelper {
/**
* Object responsible for passing on data to a specific RingBuffer event.
*/
- private final EventTranslator<Log4jEventWrapper> translator = new EventTranslator<Log4jEventWrapper>() {
+ private final EventTranslatorTwoArg<Log4jEventWrapper, LogEvent, AsyncLoggerConfig> translator
+ = new EventTranslatorTwoArg<Log4jEventWrapper, LogEvent, AsyncLoggerConfig>() {
+
@Override
- public void translateTo(final Log4jEventWrapper event,
- final long sequence) {
- event.event = currentLogEvent.get();
- event.loggerConfig = asyncLoggerConfig;
+ public void translateTo(Log4jEventWrapper ringBufferElement, long sequence,
+ LogEvent logEvent, AsyncLoggerConfig loggerConfig) {
+ ringBufferElement.event = logEvent;
+ ringBufferElement.loggerConfig = loggerConfig;
}
};
- private final ThreadLocal<LogEvent> currentLogEvent = new ThreadLocal<LogEvent>();
private final AsyncLoggerConfig asyncLoggerConfig;
public AsyncLoggerConfigHelper(final AsyncLoggerConfig asyncLoggerConfig) {
@@ -277,11 +278,9 @@ class AsyncLoggerConfigHelper {
executor.shutdown(); // finally, kill the processor thread
executor = null; // release reference to allow GC
}
-
+
public void callAppendersFromAnotherThread(final LogEvent event) {
- currentLogEvent.set(event);
- disruptor.publishEvent(translator);
- currentLogEvent.set(null); // clear reference to allow GC
+ disruptor.getRingBuffer().publishEvent(translator, event, asyncLoggerConfig);
}
}
Modified: logging/log4j/log4j2/trunk/src/changes/changes.xml
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/src/changes/changes.xml?rev=1532427&r1=1532426&r2=1532427&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/src/changes/changes.xml (original)
+++ logging/log4j/log4j2/trunk/src/changes/changes.xml Tue Oct 15 16:56:32 2013
@@ -21,6 +21,10 @@
</properties>
<body>
<release version="2.0RC1" date="2013-MM-DD" description="Bug fixes and enhancements">
+ <action issue="LOG4J2-425" dev="rpopma" type="fix">
+ Resolved memory leak by populating AsyncLoggerConfigHelper ring buffer
+ via EventTranslatorTwoArg, eliminating the need for a ThreadLocal.
+ </action>
<action issue="LOG4J2-420" dev="ggregory" type="add">
Create a lookup for resource bundle substitution.
</action>