View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements. See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to You under the Apache license, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License. You may obtain a copy of the License at
8    *
9    *      http://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the license for the specific language governing permissions and
15   * limitations under the license.
16   */
17  
18  package org.apache.logging.log4j.core.util;
19  
20  /**
21   * Prefixes thread names with {@code "Log4j2-"}.
22   */
23  public class Log4jThread extends Thread {
24  
25      private static final String PREFIX = "Log4j2-";
26  
27      private static int threadInitNumber;
28  
29      private static synchronized int nextThreadNum() {
30          return threadInitNumber++;
31      }
32  
33      private static String toThreadName(final Object name) {
34          return PREFIX + name;
35      }
36  
37      public Log4jThread() {
38          super(toThreadName(nextThreadNum()));
39      }
40  
41      public Log4jThread(final Runnable target) {
42          super(target, toThreadName(nextThreadNum()));
43      }
44  
45      public Log4jThread(final Runnable target, final String name) {
46          super(target, toThreadName(name));
47      }
48  
49      public Log4jThread(final String name) {
50          super(toThreadName(name));
51      }
52  
53      public Log4jThread(final ThreadGroup group, final Runnable target) {
54          super(group, target, toThreadName(nextThreadNum()));
55      }
56  
57      public Log4jThread(final ThreadGroup group, final Runnable target, final String name) {
58          super(group, target, toThreadName(name));
59      }
60  
61      public Log4jThread(final ThreadGroup group, final Runnable target, final String name, final long stackSize) {
62          super(group, target, toThreadName(name), stackSize);
63      }
64  
65      public Log4jThread(final ThreadGroup group, final String name) {
66          super(group, toThreadName(name));
67      }
68  
69  }