Index: log4j-core/src/main/java/org/apache/logging/log4j/core/async/AsyncLoggerConfigDisruptor.java IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== --- log4j-core/src/main/java/org/apache/logging/log4j/core/async/AsyncLoggerConfigDisruptor.java (revision 808058268c9b7acd1c0f008fba7284fa104365d1) +++ log4j-core/src/main/java/org/apache/logging/log4j/core/async/AsyncLoggerConfigDisruptor.java (revision ) @@ -16,8 +16,6 @@ */ package org.apache.logging.log4j.core.async; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; import java.util.concurrent.ThreadFactory; import org.apache.logging.log4j.Level; @@ -28,7 +26,6 @@ import org.apache.logging.log4j.core.impl.MutableLogEvent; import org.apache.logging.log4j.core.impl.ReusableLogEventFactory; import org.apache.logging.log4j.core.jmx.RingBufferAdmin; -import org.apache.logging.log4j.core.util.Constants; import org.apache.logging.log4j.message.ReusableMessage; import org.apache.logging.log4j.status.StatusLogger; @@ -177,14 +174,11 @@ } }; - private static final ThreadFactory THREAD_FACTORY = new DaemonThreadFactory("AsyncLoggerConfig-"); - private int ringBufferSize; private AsyncEventRouter asyncEventRouter; private Boolean mutable = Boolean.FALSE; private volatile Disruptor disruptor; - private ExecutorService executor; private long backgroundThreadId; // LOG4J2-471 private EventFactory factory; private EventTranslatorTwoArg translator; @@ -215,16 +209,23 @@ LOGGER.trace("AsyncLoggerConfigDisruptor creating new disruptor for this configuration."); ringBufferSize = DisruptorUtil.calculateRingBufferSize("AsyncLoggerConfig.RingBufferSize"); final WaitStrategy waitStrategy = DisruptorUtil.createWaitStrategy("AsyncLoggerConfig.WaitStrategy"); - executor = Executors.newSingleThreadExecutor(THREAD_FACTORY); - backgroundThreadId = DisruptorUtil.getExecutorThreadId(executor); + + final ThreadFactory threadFactory = new DaemonThreadFactory("AsyncLoggerConfig-") { + @Override + public Thread newThread(final Runnable r) { + final Thread result = super.newThread(r); + backgroundThreadId = result.getId(); + return result; + } + }; asyncEventRouter = AsyncEventRouterFactory.create(); translator = mutable ? MUTABLE_TRANSLATOR : TRANSLATOR; factory = mutable ? MUTABLE_FACTORY : FACTORY; - disruptor = new Disruptor<>(factory, ringBufferSize, executor, ProducerType.MULTI, waitStrategy); + disruptor = new Disruptor<>(factory, ringBufferSize, threadFactory, ProducerType.MULTI, waitStrategy); final ExceptionHandler errorHandler = DisruptorUtil.getAsyncLoggerConfigExceptionHandler(); - disruptor.handleExceptionsWith(errorHandler); + disruptor.setDefaultExceptionHandler(errorHandler); final Log4jEventWrapperHandler[] handlers = {new Log4jEventWrapperHandler()}; disruptor.handleEventsWith(handlers); @@ -260,10 +261,7 @@ } } temp.shutdown(); // busy-spins until all events currently in the disruptor have been processed - - LOGGER.trace("AsyncLoggerConfigDisruptor: shutting down disruptor executor for this configuration."); - executor.shutdown(); // finally, kill the processor thread - executor = null; // release reference to allow GC + LOGGER.trace("AsyncLoggerConfigDisruptor: disruptor has been shut down."); if (DiscardingAsyncEventRouter.getDiscardCount(asyncEventRouter) > 0) { LOGGER.trace("AsyncLoggerConfigDisruptor: {} discarded {} events.", asyncEventRouter, Index: log4j-core/src/main/java/org/apache/logging/log4j/core/async/AsyncLoggerDisruptor.java IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== --- log4j-core/src/main/java/org/apache/logging/log4j/core/async/AsyncLoggerDisruptor.java (revision 808058268c9b7acd1c0f008fba7284fa104365d1) +++ log4j-core/src/main/java/org/apache/logging/log4j/core/async/AsyncLoggerDisruptor.java (revision ) @@ -17,8 +17,7 @@ package org.apache.logging.log4j.core.async; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; +import java.util.concurrent.ThreadFactory; import org.apache.logging.log4j.Level; import org.apache.logging.log4j.core.jmx.RingBufferAdmin; @@ -42,7 +41,6 @@ private static final StatusLogger LOGGER = StatusLogger.getLogger(); private volatile Disruptor disruptor; - private ExecutorService executor; private String contextName; private boolean useThreadLocalTranslator = true; @@ -81,15 +79,22 @@ LOGGER.trace("[{}] AsyncLoggerDisruptor creating new disruptor for this context.", contextName); ringBufferSize = DisruptorUtil.calculateRingBufferSize("AsyncLogger.RingBufferSize"); final WaitStrategy waitStrategy = DisruptorUtil.createWaitStrategy("AsyncLogger.WaitStrategy"); - executor = Executors.newSingleThreadExecutor(new DaemonThreadFactory("AsyncLogger[" + contextName + "]")); - backgroundThreadId = DisruptorUtil.getExecutorThreadId(executor); + + final ThreadFactory threadFactory = new DaemonThreadFactory("AsyncLogger[" + contextName + "]") { + @Override + public Thread newThread(final Runnable r) { + final Thread result = super.newThread(r); + backgroundThreadId = result.getId(); + return result; + } + }; asyncEventRouter = AsyncEventRouterFactory.create(); - disruptor = new Disruptor<>(RingBufferLogEvent.FACTORY, ringBufferSize, executor, ProducerType.MULTI, + disruptor = new Disruptor<>(RingBufferLogEvent.FACTORY, ringBufferSize, threadFactory, ProducerType.MULTI, waitStrategy); final ExceptionHandler errorHandler = DisruptorUtil.getAsyncLoggerExceptionHandler(); - disruptor.handleExceptionsWith(errorHandler); + disruptor.setDefaultExceptionHandler(errorHandler); final RingBufferLogEventHandler[] handlers = {new RingBufferLogEventHandler()}; disruptor.handleEventsWith(handlers); @@ -128,10 +133,7 @@ } } temp.shutdown(); // busy-spins until all events currently in the disruptor have been processed - - LOGGER.trace("[{}] AsyncLoggerDisruptor: shutting down disruptor executor.", contextName); - executor.shutdown(); // finally, kill the processor thread - executor = null; + LOGGER.trace("[{}] AsyncLoggerDisruptor: disruptor has been shut down.", contextName); if (DiscardingAsyncEventRouter.getDiscardCount(asyncEventRouter) > 0) { LOGGER.trace("AsyncLoggerDisruptor: {} discarded {} events.", asyncEventRouter,