Remove need for synchronization in Log4jThread

Use AtomicLong instead of a lock.


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

Branch: refs/heads/master
Commit: 45961ef88e0d9c8eaf5b4c1eff90ac312176fd05
Parents: 8a74e22
Author: Matt Sicker <[email protected]>
Authored: Sat Dec 31 12:45:58 2016 -0600
Committer: Matt Sicker <[email protected]>
Committed: Sat Dec 31 13:34:54 2016 -0600

----------------------------------------------------------------------
 .../java/org/apache/logging/log4j/core/util/Log4jThread.java | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/45961ef8/log4j-core/src/main/java/org/apache/logging/log4j/core/util/Log4jThread.java
----------------------------------------------------------------------
diff --git 
a/log4j-core/src/main/java/org/apache/logging/log4j/core/util/Log4jThread.java 
b/log4j-core/src/main/java/org/apache/logging/log4j/core/util/Log4jThread.java
index b92f181..7657fdc 100644
--- 
a/log4j-core/src/main/java/org/apache/logging/log4j/core/util/Log4jThread.java
+++ 
b/log4j-core/src/main/java/org/apache/logging/log4j/core/util/Log4jThread.java
@@ -17,6 +17,8 @@
 
 package org.apache.logging.log4j.core.util;
 
+import java.util.concurrent.atomic.AtomicLong;
+
 /**
  * Prefixes thread names with {@code "Log4j2-"}.
  */
@@ -24,10 +26,10 @@ public class Log4jThread extends Thread {
 
     static final String PREFIX = "Log4j2-";
 
-    private static int threadInitNumber;
+    private static final AtomicLong threadInitNumber = new AtomicLong();
 
-    private static synchronized int nextThreadNum() {
-        return threadInitNumber++;
+    private static long nextThreadNum() {
+        return threadInitNumber.getAndIncrement();
     }
 
     private static String toThreadName(final Object name) {

Reply via email to