您的位置:首页 > 其它

日志系列之Log4j2 Garbage-free模式

2017-12-14 20:33 946 查看
Garbage-free核心思想:避免或减少对象的创建;

实现方式

对象复用(threadlocal、jvm级别复用);

避免临时对象的创建;

From version 2.6, Log4j runs in “garbage free” mode by default where objects and buffers are reused and no temporary objects are allocated as much as possible. There is also a “low garbage” mode which is not completely garbage free but does not use ThreadLocal fields. This is the default mode when Log4j detects it is running in a web application.

检测web应用

  方式:检测javax.servlet.Servlet是否在classpath上;

系统参数配置

log4j2.enableThreadlocals - if “true” (the default for non-web applications) objects are stored in ThreadLocal fields and reused, otherwise new objects are created for each log event.

log4j2.enableDirectEncoders - if “true” (the default) log events are converted to text and this text is converted to bytes without creating temporary objects.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: