zoukankan      html  css  js  c++  java
  • log4j2用Log4jContextSelector启动参数配置全局异步日志是如何使用disruptor

    log4j2用asyncRoot配置异步日志是如何使用disruptor差异有几个:

    给disruptor实例的EventFactory不同

    此处EventFactory采用的是RingBufferLogEvent.FACTORY,newInstance逻辑大致是:

    public RingBufferLogEvent newInstance() {
        final RingBufferLogEvent result = new RingBufferLogEvent();
        if (Constants.ENABLE_THREADLOCALS) {
            result.messageText = new StringBuilder(Constants.INITIAL_REUSABLE_MESSAGE_SIZE);
            result.parameters = new Object[10];
        }
        return result;
    }
    

    创建的是 RingBufferLogEvent实例。该对象封装了日志输出的执行动作等。

    给disruptor的threadFactory的参数不同

    thread factory的名字是"AsyncLogger[" + contextName + "]"

    给disruptor的EventHandler不同

    此处用RingBufferLogEventHandler,对接RingBufferLogEvent实例处理日志写出。

    给disrupto的Translator不同

    此处用RingBufferLogEventTranslator,对接RingBufferLogEvent实例组装日志信息。

    事件进入队列方式不同

    封装了一个叫tryPublish的方法进入队列。

  • 相关阅读:
    IDEA添加注释模板
    Docker安装Mysql
    Linux使用
    Linux使用
    Spring Cloud入门 (5)
    在IDEA中将SpringBoot项目打包成jar包
    Linux使用
    Linux使用
    Linux使用- 虚拟机安装 Linux
    Spring Cloud入门 (4)
  • 原文地址:https://www.cnblogs.com/simoncook/p/10990266.html
Copyright © 2011-2022 走看看