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
020/**
021 * Prefixes thread names with {@code "Log4j2-"}.
022 */
023public class Log4jThread extends Thread {
024
025    private static final String PREFIX = "Log4j2-";
026
027    private static int threadInitNumber;
028
029    private static synchronized int nextThreadNum() {
030        return threadInitNumber++;
031    }
032
033    private static String toThreadName(final Object name) {
034        return PREFIX + name;
035    }
036
037    public Log4jThread() {
038        super(toThreadName(nextThreadNum()));
039    }
040
041    public Log4jThread(final Runnable target) {
042        super(target, toThreadName(nextThreadNum()));
043    }
044
045    public Log4jThread(final Runnable target, final String name) {
046        super(target, toThreadName(name));
047    }
048
049    public Log4jThread(final String name) {
050        super(toThreadName(name));
051    }
052
053    public Log4jThread(final ThreadGroup group, final Runnable target) {
054        super(group, target, toThreadName(nextThreadNum()));
055    }
056
057    public Log4jThread(final ThreadGroup group, final Runnable target, final String name) {
058        super(group, target, toThreadName(name));
059    }
060
061    public Log4jThread(final ThreadGroup group, final Runnable target, final String name, final long stackSize) {
062        super(group, target, toThreadName(name), stackSize);
063    }
064
065    public Log4jThread(final ThreadGroup group, final String name) {
066        super(group, toThreadName(name));
067    }
068
069}