From 2d153e56e731d77e5c2a651b028668c87746cdbd Mon Sep 17 00:00:00 2001 From: xuxueli <931591021@qq.com> Date: Fri, 12 Jun 2020 17:53:55 +0800 Subject: [PATCH] =?UTF-8?q?=E6=97=A5=E5=BF=97=E7=BB=84=E4=BB=B6=E9=80=BB?= =?UTF-8?q?=E8=BE=91=E8=B0=83=E6=95=B4=EF=BC=9A=E6=97=A5=E5=BF=97=E7=BB=84?= =?UTF-8?q?=E4=BB=B6=E6=94=B9=E4=B8=BA=E9=80=9A=E8=BF=87=20XxlJobContent?= =?UTF-8?q?=20=E8=8E=B7=E5=8F=96=E4=BB=BB=E5=8A=A1=E4=B8=8A=E4=B8=8B?= =?UTF-8?q?=E6=96=87=E5=B9=B6=E5=8C=B9=E9=85=8D=E5=86=99=E5=85=A5=E5=AF=B9?= =?UTF-8?q?=E5=BA=94=E6=97=A5=E5=BF=97=E6=96=87=E4=BB=B6=EF=BC=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- doc/XXL-JOB官方文档.md | 3 ++- .../main/java/com/xxl/job/core/context/XxlJobContext.java | 2 +- .../com/xxl/job/core/handler/impl/ScriptJobHandler.java | 2 +- .../main/java/com/xxl/job/core/log/XxlJobFileAppender.java | 5 ----- .../src/main/java/com/xxl/job/core/log/XxlJobLogger.java | 4 +++- .../src/main/java/com/xxl/job/core/thread/JobThread.java | 2 -- .../com/xxl/job/core/thread/TriggerCallbackThread.java | 7 ++++++- 7 files changed, 13 insertions(+), 12 deletions(-) diff --git a/doc/XXL-JOB官方文档.md b/doc/XXL-JOB官方文档.md index a66a4981..b354ffce 100644 --- a/doc/XXL-JOB官方文档.md +++ b/doc/XXL-JOB官方文档.md @@ -1992,7 +1992,8 @@ data: post-data - 4、多个项目依赖升级至较新稳定版本,如netty、spring、springboot等; - 5、通用HTTP任务Handler(httpJobHandler)优化:修复 "setDoOutput(true)" 导致任务请求GetMethod失效问题; - 6、新增任务属性 "XxlJobContent" ,统一维护任务上下文信息,包括任务ID、分片参数等,方便运行时存取任务相关信息; - - 废弃 "ShardingUtil" 组件:改用 "XxlJobContext.getXxlJobContext().getShardIndex()/getShardTotal();" 获取分片参数; + - 6.1、废弃 "ShardingUtil" 组件:改用 "XxlJobContext.getXxlJobContext().getShardIndex()/getShardTotal();" 获取分片参数; + - 6.2、日志组件逻辑调整:日志组件改为通过 XxlJobContent 获取任务上下文并匹配写入对应日志文件; - 7、[规划中]任务触发参数优化:支持选择 "Cron触发"、"固定间隔时间触发"、"指定时间点触发"、"不选择" 等; ### 7.32 版本 v2.3.0 Release Notes[规划中] diff --git a/xxl-job-core/src/main/java/com/xxl/job/core/context/XxlJobContext.java b/xxl-job-core/src/main/java/com/xxl/job/core/context/XxlJobContext.java index a0129069..4e791575 100644 --- a/xxl-job-core/src/main/java/com/xxl/job/core/context/XxlJobContext.java +++ b/xxl-job-core/src/main/java/com/xxl/job/core/context/XxlJobContext.java @@ -55,7 +55,7 @@ public class XxlJobContext { // ---------------------- tool ---------------------- - private static InheritableThreadLocal contextHolder = new InheritableThreadLocal(); + private static InheritableThreadLocal contextHolder = new InheritableThreadLocal(); // support for child thread of job handler) public static void setXxlJobContext(XxlJobContext xxlJobContext){ contextHolder.set(xxlJobContext); diff --git a/xxl-job-core/src/main/java/com/xxl/job/core/handler/impl/ScriptJobHandler.java b/xxl-job-core/src/main/java/com/xxl/job/core/handler/impl/ScriptJobHandler.java index f9357e81..4fa1bc00 100644 --- a/xxl-job-core/src/main/java/com/xxl/job/core/handler/impl/ScriptJobHandler.java +++ b/xxl-job-core/src/main/java/com/xxl/job/core/handler/impl/ScriptJobHandler.java @@ -68,7 +68,7 @@ public class ScriptJobHandler extends IJobHandler { } // log file - String logFileName = XxlJobFileAppender.contextHolder.get(); + String logFileName = XxlJobContext.getXxlJobContext().getJobLogFileName(); // script params:0=param、1=分片序号、2=分片总数 String[] scriptParams = new String[3]; diff --git a/xxl-job-core/src/main/java/com/xxl/job/core/log/XxlJobFileAppender.java b/xxl-job-core/src/main/java/com/xxl/job/core/log/XxlJobFileAppender.java index 3fa8c4de..ff0585b5 100644 --- a/xxl-job-core/src/main/java/com/xxl/job/core/log/XxlJobFileAppender.java +++ b/xxl-job-core/src/main/java/com/xxl/job/core/log/XxlJobFileAppender.java @@ -14,11 +14,6 @@ import java.util.Date; */ public class XxlJobFileAppender { private static Logger logger = LoggerFactory.getLogger(XxlJobFileAppender.class); - - // for JobThread (support log for child thread of job handler) - //public static ThreadLocal contextHolder = new ThreadLocal(); - public static final InheritableThreadLocal contextHolder = new InheritableThreadLocal(); - /** * log base path diff --git a/xxl-job-core/src/main/java/com/xxl/job/core/log/XxlJobLogger.java b/xxl-job-core/src/main/java/com/xxl/job/core/log/XxlJobLogger.java index caf47b90..d9dd4019 100644 --- a/xxl-job-core/src/main/java/com/xxl/job/core/log/XxlJobLogger.java +++ b/xxl-job-core/src/main/java/com/xxl/job/core/log/XxlJobLogger.java @@ -1,5 +1,6 @@ package com.xxl.job.core.log; +import com.xxl.job.core.context.XxlJobContext; import com.xxl.job.core.util.DateUtil; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -38,7 +39,8 @@ public class XxlJobLogger { String formatAppendLog = stringBuffer.toString(); // appendlog - String logFileName = XxlJobFileAppender.contextHolder.get(); + String logFileName = XxlJobContext.getXxlJobContext().getJobLogFileName(); + if (logFileName!=null && logFileName.trim().length()>0) { XxlJobFileAppender.appendLog(logFileName, formatAppendLog); } else { diff --git a/xxl-job-core/src/main/java/com/xxl/job/core/thread/JobThread.java b/xxl-job-core/src/main/java/com/xxl/job/core/thread/JobThread.java index aa4efb94..48776c2c 100644 --- a/xxl-job-core/src/main/java/com/xxl/job/core/thread/JobThread.java +++ b/xxl-job-core/src/main/java/com/xxl/job/core/thread/JobThread.java @@ -123,8 +123,6 @@ public class JobThread extends Thread{ triggerParam.getBroadcastIndex(), triggerParam.getBroadcastTotal())); - XxlJobFileAppender.contextHolder.set(logFileName); - // execute XxlJobLogger.log("
----------- xxl-job job execute start -----------
----------- Param:" + triggerParam.getExecutorParams()); diff --git a/xxl-job-core/src/main/java/com/xxl/job/core/thread/TriggerCallbackThread.java b/xxl-job-core/src/main/java/com/xxl/job/core/thread/TriggerCallbackThread.java index d2b2a407..3d5bfb72 100644 --- a/xxl-job-core/src/main/java/com/xxl/job/core/thread/TriggerCallbackThread.java +++ b/xxl-job-core/src/main/java/com/xxl/job/core/thread/TriggerCallbackThread.java @@ -3,6 +3,7 @@ package com.xxl.job.core.thread; import com.xxl.job.core.biz.AdminBiz; import com.xxl.job.core.biz.model.HandleCallbackParam; import com.xxl.job.core.biz.model.ReturnT; +import com.xxl.job.core.context.XxlJobContext; import com.xxl.job.core.enums.RegistryConfig; import com.xxl.job.core.executor.XxlJobExecutor; import com.xxl.job.core.log.XxlJobFileAppender; @@ -187,7 +188,11 @@ public class TriggerCallbackThread { private void callbackLog(List callbackParamList, String logContent){ for (HandleCallbackParam callbackParam: callbackParamList) { String logFileName = XxlJobFileAppender.makeLogFileName(new Date(callbackParam.getLogDateTim()), callbackParam.getLogId()); - XxlJobFileAppender.contextHolder.set(logFileName); + XxlJobContext.setXxlJobContext(new XxlJobContext( + -1, + logFileName, + -1, + -1)); XxlJobLogger.log(logContent); } }