首页  |  知识库  |  资源下载  |  在线工具  |  A-Z  •  JAR  •  名词查         

关于Log4j2源码包中Log4jThread自定义线程Thread主体类实现名称和编码的源码分析

标签:Log4jThread,自定义线程,log4j2源码     发布时间:2018-04-06

一、前言

关于log4j2log4j-core源码包org.apache.logging.log4j.core.util.Log4jThread线程类,对java.lang.Thread类进行自定义扩展-定义了扩展"Log4j2-"线程名称并AtomicLong自增长编号定义方式,具体参见源码说明。

二、源码说明

package org.apache.logging.log4j.core.util;@b@@b@import java.util.concurrent.atomic.AtomicLong;@b@@b@/**@b@ * Prefixes thread names with {@code "Log4j2-"}.@b@ */@b@public class Log4jThread extends Thread {@b@@b@    static final String PREFIX = "Log4j2-";@b@@b@    private static final AtomicLong threadInitNumber = new AtomicLong();@b@@b@    private static long nextThreadNum() {@b@        return threadInitNumber.getAndIncrement();@b@    }@b@@b@    private static String toThreadName(final Object name) {@b@        return PREFIX + name;@b@    }@b@@b@    public Log4jThread() {@b@        super(toThreadName(nextThreadNum()));@b@    }@b@@b@    public Log4jThread(final Runnable target) {@b@        super(target, toThreadName(nextThreadNum()));@b@    }@b@@b@    public Log4jThread(final Runnable target, final String name) {@b@        super(target, toThreadName(name));@b@    }@b@@b@    public Log4jThread(final String name) {@b@        super(toThreadName(name));@b@    }@b@@b@    public Log4jThread(final ThreadGroup group, final Runnable target) {@b@        super(group, target, toThreadName(nextThreadNum()));@b@    }@b@@b@    public Log4jThread(final ThreadGroup group, final Runnable target, final String name) {@b@        super(group, target, toThreadName(name));@b@    }@b@@b@    public Log4jThread(final ThreadGroup group, final Runnable target, final String name, final long stackSize) {@b@        super(group, target, toThreadName(name), stackSize);@b@    }@b@@b@    public Log4jThread(final ThreadGroup group, final String name) {@b@        super(group, toThreadName(name));@b@    }@b@@b@}
  • ◆ 相关内容