logging-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rpo...@apache.org
Subject svn commit: r1498051 - in /logging/log4j/log4j2/trunk: core/src/main/java/org/apache/logging/log4j/core/async/ src/changes/
Date Sun, 30 Jun 2013 02:13:21 GMT
Author: rpopma
Date: Sun Jun 30 02:13:21 2013
New Revision: 1498051

URL: http://svn.apache.org/r1498051
Log:
Fix for LOG4J2-280: async logger threads are now daemon threads

Added:
    logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/async/DaemonThreadFactory.java
  (with props)
Modified:
    logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/async/AsyncLogger.java
    logging/log4j/log4j2/trunk/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/core/src/main/java/org/apache/logging/log4j/core/async/AsyncLogger.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/async/AsyncLogger.java?rev=1498051&r1=1498050&r2=1498051&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/async/AsyncLogger.java
(original)
+++ logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/async/AsyncLogger.java
Sun Jun 30 02:13:21 2013
@@ -82,7 +82,7 @@ public class AsyncLogger extends Logger 
     private static Clock clock = ClockFactory.getClock();
 
     private static ExecutorService executor = Executors
-            .newSingleThreadExecutor();
+            .newSingleThreadExecutor(new DaemonThreadFactory("AsyncLogger-"));
     private ThreadLocal<Info> threadlocalInfo = new ThreadLocal<Info>();
 
     static {

Modified: logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/async/AsyncLoggerConfigHelper.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/async/AsyncLoggerConfigHelper.java?rev=1498051&r1=1498050&r2=1498051&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/async/AsyncLoggerConfigHelper.java
(original)
+++ logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/async/AsyncLoggerConfigHelper.java
Sun Jun 30 02:13:21 2013
@@ -63,7 +63,9 @@ class AsyncLoggerConfigHelper {
     private static final Logger LOGGER = StatusLogger.getLogger();
 
     private static volatile Disruptor<Log4jEventWrapper> disruptor;
-    private static ExecutorService executor = Executors.newSingleThreadExecutor();
+    private static ExecutorService executor = Executors
+            .newSingleThreadExecutor(new DaemonThreadFactory(
+                    "AsyncLoggerConfig-"));
 
     private static volatile int count = 0;
 
@@ -104,10 +106,10 @@ class AsyncLoggerConfigHelper {
         }
         int ringBufferSize = calculateRingBufferSize();
         WaitStrategy waitStrategy = createWaitStrategy();
-        disruptor = new Disruptor<Log4jEventWrapper>(FACTORY,
-                ringBufferSize, executor, ProducerType.MULTI, waitStrategy);
+        disruptor = new Disruptor<Log4jEventWrapper>(FACTORY, ringBufferSize,
+                executor, ProducerType.MULTI, waitStrategy);
         EventHandler<Log4jEventWrapper>[] handlers = new Log4jEventWrapperHandler[]
{//
-                new Log4jEventWrapperHandler() };
+        new Log4jEventWrapperHandler() };
         disruptor.handleExceptionsWith(getExceptionHandler());
         disruptor.handleEventsWith(handlers);
 

Added: logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/async/DaemonThreadFactory.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/async/DaemonThreadFactory.java?rev=1498051&view=auto
==============================================================================
--- logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/async/DaemonThreadFactory.java
(added)
+++ logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/async/DaemonThreadFactory.java
Sun Jun 30 02:13:21 2013
@@ -0,0 +1,50 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache license, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the license for the specific language governing permissions and
+ * limitations under the license.
+ */
+package org.apache.logging.log4j.core.async;
+
+import java.util.concurrent.ThreadFactory;
+import java.util.concurrent.atomic.AtomicInteger;
+
+/**
+ * ThreadFactory that creates daemon threads for the async loggers.
+ */
+public class DaemonThreadFactory implements ThreadFactory {
+
+    final ThreadGroup group;
+    final AtomicInteger threadNumber = new AtomicInteger(1);
+    final String threadNamePrefix;
+
+    public DaemonThreadFactory(String threadNamePrefix) {
+        this.threadNamePrefix = threadNamePrefix;
+        SecurityManager securityManager = System.getSecurityManager();
+        group = (securityManager != null) ? securityManager.getThreadGroup()
+                : Thread.currentThread().getThreadGroup();
+    }
+
+    public Thread newThread(Runnable runnable) {
+        Thread thread = new Thread(group, runnable, threadNamePrefix
+                + threadNumber.getAndIncrement(), 0);
+        if (!thread.isDaemon()) {
+            thread.setDaemon(true);
+        }
+        if (thread.getPriority() != Thread.NORM_PRIORITY) {
+            thread.setPriority(Thread.NORM_PRIORITY);
+        }
+        return thread;
+    }
+
+}

Propchange: logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/async/DaemonThreadFactory.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: logging/log4j/log4j2/trunk/src/changes/changes.xml
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/src/changes/changes.xml?rev=1498051&r1=1498050&r2=1498051&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/src/changes/changes.xml (original)
+++ logging/log4j/log4j2/trunk/src/changes/changes.xml Sun Jun 30 02:13:21 2013
@@ -21,6 +21,9 @@
   </properties>
   <body>
     <release version="2.0-beta8" date="2013-??-??" description="Bug fixes and enhancements">
+      <action issue="LOG4J2-280" dev="rpopma" type="fix">
+        AsyncLogger threads are now daemon threads and won't prevent the JVM from shutting
down anymore.
+      </action>
       <action issue="LOG4J2-295" dev="rpopma" type="fix">
         Fast(Rolling)FileAppender now correctly handles messages exceeding the buffer size.
       </action>



Mime
View raw message