001/* 002 * Licensed to the Apache Software Foundation (ASF) under one or more 003 * contributor license agreements. See the NOTICE file distributed with 004 * this work for additional information regarding copyright ownership. 005 * The ASF licenses this file to You under the Apache license, Version 2.0 006 * (the "License"); you may not use this file except in compliance with 007 * the License. You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the license for the specific language governing permissions and 015 * limitations under the license. 016 */ 017 018package org.apache.logging.log4j.core.util; 019 020import java.util.concurrent.atomic.AtomicLong; 021 022/** 023 * Prefixes thread names with {@code "Log4j2-"}. 024 */ 025public class Log4jThread extends Thread { 026 027 static final String PREFIX = "Log4j2-"; 028 029 private static final AtomicLong threadInitNumber = new AtomicLong(); 030 031 private static long nextThreadNum() { 032 return threadInitNumber.getAndIncrement(); 033 } 034 035 private static String toThreadName(final Object name) { 036 return PREFIX + name; 037 } 038 039 public Log4jThread() { 040 super(toThreadName(nextThreadNum())); 041 } 042 043 public Log4jThread(final Runnable target) { 044 super(target, toThreadName(nextThreadNum())); 045 } 046 047 public Log4jThread(final Runnable target, final String name) { 048 super(target, toThreadName(name)); 049 } 050 051 public Log4jThread(final String name) { 052 super(toThreadName(name)); 053 } 054 055 public Log4jThread(final ThreadGroup group, final Runnable target) { 056 super(group, target, toThreadName(nextThreadNum())); 057 } 058 059 public Log4jThread(final ThreadGroup group, final Runnable target, final String name) { 060 super(group, target, toThreadName(name)); 061 } 062 063 public Log4jThread(final ThreadGroup group, final Runnable target, final String name, final long stackSize) { 064 super(group, target, toThreadName(name), stackSize); 065 } 066 067 public Log4jThread(final ThreadGroup group, final String name) { 068 super(group, toThreadName(name)); 069 } 070 071}