|
@@ -1,13 +1,12 @@
|
|
|
package cn.com.qmth.examcloud.task.base;
|
|
|
|
|
|
+import org.apache.logging.log4j.ThreadContext;
|
|
|
import org.quartz.Job;
|
|
|
import org.quartz.JobExecutionContext;
|
|
|
import org.quartz.JobExecutionException;
|
|
|
-import org.slf4j.MDC;
|
|
|
|
|
|
import cn.com.qmth.examcloud.commons.logging.ExamCloudLog;
|
|
|
import cn.com.qmth.examcloud.commons.logging.ExamCloudLogFactory;
|
|
|
-import cn.com.qmth.examcloud.commons.logging.SLF4JImpl;
|
|
|
import cn.com.qmth.examcloud.commons.util.JsonUtil;
|
|
|
import cn.com.qmth.examcloud.commons.util.ThreadLocalUtil;
|
|
|
import cn.com.qmth.examcloud.web.support.SpringContextHolder;
|
|
@@ -25,10 +24,7 @@ public class DistributionJob implements Job {
|
|
|
@Override
|
|
|
public void execute(JobExecutionContext context) throws JobExecutionException {
|
|
|
String traceId = ThreadLocalUtil.next();
|
|
|
- // 设置MDC
|
|
|
- if (TASK_LOG instanceof SLF4JImpl) {
|
|
|
- MDC.put("TRACE_ID", traceId);
|
|
|
- }
|
|
|
+ ThreadContext.put("TRACE_ID", traceId);
|
|
|
ScheduleJob scheduleJob = null;
|
|
|
try {
|
|
|
scheduleJob = (ScheduleJob) context.getMergedJobDataMap().get("scheduleJob");
|
|
@@ -42,14 +38,13 @@ public class DistributionJob implements Job {
|
|
|
task.execute(scheduleJob, traceId);
|
|
|
} catch (Exception e) {
|
|
|
if (TASK_LOG.isErrorEnabled()) {
|
|
|
- TASK_LOG.error("fail to distribute job. job detail :" + JsonUtil.toJson(scheduleJob), e);
|
|
|
+ TASK_LOG.error(
|
|
|
+ "fail to distribute job. job detail :" + JsonUtil.toJson(scheduleJob), e);
|
|
|
}
|
|
|
throw new JobExecutionException(e);
|
|
|
} finally {
|
|
|
- // 清理MDC
|
|
|
- if (TASK_LOG instanceof SLF4JImpl) {
|
|
|
- MDC.clear();
|
|
|
- }
|
|
|
+ // 清理log4j线程上下文
|
|
|
+ ThreadContext.clearAll();
|
|
|
}
|
|
|
|
|
|
}
|