Class Log4jThreadFactory
- java.lang.Object
-
- org.apache.logging.log4j.core.util.Log4jThreadFactory
-
- All Implemented Interfaces:
java.util.concurrent.ThreadFactory
public class Log4jThreadFactory extends java.lang.Object implements java.util.concurrent.ThreadFactoryCreatesLog4jThreads.- Since:
- 2.7
-
-
Field Summary
Fields Modifier and Type Field Description private booleandaemonprivate static java.util.concurrent.atomic.AtomicIntegerFACTORY_NUMBERprivate java.lang.ThreadGroupgroupprivate static java.lang.StringPREFIXprivate intpriorityprivate static java.util.concurrent.atomic.AtomicIntegerTHREAD_NUMBERprivate java.lang.StringthreadNamePrefix
-
Constructor Summary
Constructors Constructor Description Log4jThreadFactory(java.lang.String threadFactoryName, boolean daemon, int priority)Constructs an initialized thread factory.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static Log4jThreadFactorycreateDaemonThreadFactory(java.lang.String threadFactoryName)Creates a new daemon thread factory.static Log4jThreadFactorycreateThreadFactory(java.lang.String threadFactoryName)Creates a new thread factory.java.lang.ThreadnewThread(java.lang.Runnable runnable)
-
-
-
Field Detail
-
PREFIX
private static final java.lang.String PREFIX
- See Also:
- Constant Field Values
-
FACTORY_NUMBER
private static final java.util.concurrent.atomic.AtomicInteger FACTORY_NUMBER
-
THREAD_NUMBER
private static final java.util.concurrent.atomic.AtomicInteger THREAD_NUMBER
-
daemon
private final boolean daemon
-
group
private final java.lang.ThreadGroup group
-
priority
private final int priority
-
threadNamePrefix
private final java.lang.String threadNamePrefix
-
-
Constructor Detail
-
Log4jThreadFactory
public Log4jThreadFactory(java.lang.String threadFactoryName, boolean daemon, int priority)Constructs an initialized thread factory.- Parameters:
threadFactoryName- The thread factory name.daemon- Whether to create daemon threads.priority- The thread priority.
-
-
Method Detail
-
createDaemonThreadFactory
public static Log4jThreadFactory createDaemonThreadFactory(java.lang.String threadFactoryName)
Creates a new daemon thread factory.- Parameters:
threadFactoryName- The thread factory name.- Returns:
- a new daemon thread factory.
-
createThreadFactory
public static Log4jThreadFactory createThreadFactory(java.lang.String threadFactoryName)
Creates a new thread factory. This is mainly used for tests. Production code should be very careful with creating non-daemon threads since those will block application shutdown (see https://issues.apache.org/jira/browse/LOG4J2-1748).- Parameters:
threadFactoryName- The thread factory name.- Returns:
- a new daemon thread factory.
-
newThread
public java.lang.Thread newThread(java.lang.Runnable runnable)
- Specified by:
newThreadin interfacejava.util.concurrent.ThreadFactory
-
-