You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@logging.apache.org by rg...@apache.org on 2014/10/19 06:31:09 UTC

git commit: Use a thread safe collection

Repository: logging-log4j2
Updated Branches:
  refs/heads/master 453086ca3 -> fe6943fa0


Use a thread safe collection


Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/fe6943fa
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/fe6943fa
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/fe6943fa

Branch: refs/heads/master
Commit: fe6943fa0e45cb477b4296f5965d91fb722c66cc
Parents: 453086c
Author: rgoers <ra...@dslextreme.com>
Authored: Sat Oct 18 21:31:03 2014 -0700
Committer: rgoers <ra...@dslextreme.com>
Committed: Sat Oct 18 21:31:03 2014 -0700

----------------------------------------------------------------------
 .../core/util/ShutdownCallbackRegistryTest.java    | 17 +++++++----------
 1 file changed, 7 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/fe6943fa/log4j-core/src/test/java/org/apache/logging/log4j/core/util/ShutdownCallbackRegistryTest.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/util/ShutdownCallbackRegistryTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/util/ShutdownCallbackRegistryTest.java
index 56d9a58..92ec86e 100644
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/util/ShutdownCallbackRegistryTest.java
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/util/ShutdownCallbackRegistryTest.java
@@ -18,6 +18,7 @@ package org.apache.logging.log4j.core.util;
 
 import java.util.Collection;
 import java.util.LinkedList;
+import java.util.concurrent.ConcurrentLinkedQueue;
 
 import org.apache.logging.log4j.LogManager;
 import org.apache.logging.log4j.Logger;
@@ -59,7 +60,7 @@ public class ShutdownCallbackRegistryTest {
 
     public static class Registry implements ShutdownCallbackRegistry {
         private static final Logger LOGGER = StatusLogger.getLogger();
-        private static final Collection<Cancellable> CALLBACKS = new LinkedList<Cancellable>();
+        private static final Collection<Cancellable> CALLBACKS = new ConcurrentLinkedQueue<Cancellable>();
 
         @Override
         public Cancellable addShutdownCallback(final Runnable callback) {
@@ -76,20 +77,16 @@ public class ShutdownCallbackRegistryTest {
                     callback.run();
                 }
             };
-            synchronized (CALLBACKS) {
-                CALLBACKS.add(cancellable);
-            }
+            CALLBACKS.add(cancellable);
             return cancellable;
         }
 
         private static void shutdown() {
-            synchronized (CALLBACKS) {
-                for (final Runnable callback : CALLBACKS) {
-                    LOGGER.debug("Calling shutdown callback: {}", callback);
-                    callback.run();
-                }
-                CALLBACKS.clear();
+            for (final Runnable callback : CALLBACKS) {
+                LOGGER.debug("Calling shutdown callback: {}", callback);
+                callback.run();
             }
+            CALLBACKS.clear();
         }
     }