From 2a94a142e38747dc9d9acd7b6f3f14c1e9014eab Mon Sep 17 00:00:00 2001 From: xuxueli <931591021@qq.com> Date: Wed, 20 Dec 2017 21:16:06 +0800 Subject: [PATCH] =?UTF-8?q?JobHandler=E6=8F=90=E4=BE=9Binit/destroy?= =?UTF-8?q?=E6=96=B9=E6=B3=95=EF=BC=8C=E6=94=AF=E6=8C=81=E5=9C=A8JobHandle?= =?UTF-8?q?r=E5=88=9D=E5=A7=8B=E5=8C=96=E5=92=8C=E9=94=80=E6=AF=81?= =?UTF-8?q?=E6=97=B6=E8=BF=9B=E8=A1=8C=E9=99=84=E5=8A=A0=E6=93=8D=E4=BD=9C?= =?UTF-8?q?=EF=BC=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../xxl/job/core/biz/impl/ExecutorBizImpl.java | 9 ++++----- .../java/com/xxl/job/core/log/XxlJobLogger.java | 15 +++++++-------- .../java/com/xxl/job/core/thread/JobThread.java | 15 +++++++++++++++ 3 files changed, 26 insertions(+), 13 deletions(-) diff --git a/xxl-job-core/src/main/java/com/xxl/job/core/biz/impl/ExecutorBizImpl.java b/xxl-job-core/src/main/java/com/xxl/job/core/biz/impl/ExecutorBizImpl.java index 13fa9440..885ae3f9 100644 --- a/xxl-job-core/src/main/java/com/xxl/job/core/biz/impl/ExecutorBizImpl.java +++ b/xxl-job-core/src/main/java/com/xxl/job/core/biz/impl/ExecutorBizImpl.java @@ -74,7 +74,8 @@ public class ExecutorBizImpl implements ExecutorBiz { String removeOldReason = null; // valid:jobHandler + jobThread - if (GlueTypeEnum.BEAN==GlueTypeEnum.match(triggerParam.getGlueType())) { + GlueTypeEnum glueTypeEnum = GlueTypeEnum.match(triggerParam.getGlueType()); + if (GlueTypeEnum.BEAN == glueTypeEnum) { // new jobhandler IJobHandler newJobHandler = XxlJobExecutor.loadJobHandler(triggerParam.getExecutorHandler()); @@ -96,7 +97,7 @@ public class ExecutorBizImpl implements ExecutorBiz { } } - } else if (GlueTypeEnum.GLUE_GROOVY==GlueTypeEnum.match(triggerParam.getGlueType())) { + } else if (GlueTypeEnum.GLUE_GROOVY == glueTypeEnum) { // valid old jobThread if (jobThread != null && @@ -119,9 +120,7 @@ public class ExecutorBizImpl implements ExecutorBiz { return new ReturnT(ReturnT.FAIL_CODE, e.getMessage()); } } - } else if (GlueTypeEnum.GLUE_SHELL==GlueTypeEnum.match(triggerParam.getGlueType()) - || GlueTypeEnum.GLUE_PYTHON==GlueTypeEnum.match(triggerParam.getGlueType()) - || GlueTypeEnum.GLUE_NODEJS==GlueTypeEnum.match(triggerParam.getGlueType())) { + } else if (glueTypeEnum!=null && glueTypeEnum.isScript()) { // valid old jobThread if (jobThread != null && 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 32043ef2..1ea06e2d 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 @@ -24,11 +24,6 @@ public class XxlJobLogger { */ private static void logDetail(StackTraceElement callInfo, String appendLog) { - // logFileName - String logFileName = XxlJobFileAppender.contextHolder.get(); - if (logFileName==null || logFileName.trim().length()==0) { - return; - } /*// "yyyy-MM-dd HH:mm:ss [ClassName]-[MethodName]-[LineNumber]-[ThreadName] log"; StackTraceElement[] stackTraceElements = new Throwable().getStackTrace(); @@ -44,9 +39,13 @@ public class XxlJobLogger { String formatAppendLog = stringBuffer.toString(); // appendlog - XxlJobFileAppender.appendLog(logFileName, formatAppendLog); - - logger.debug(">>>>>>>>>>> [{}]: {}", logFileName, formatAppendLog); + String logFileName = XxlJobFileAppender.contextHolder.get(); + if (logFileName==null || logFileName.trim().length()==0) { + logger.info(">>>>>>>>>>> [{}]: {}", logFileName, formatAppendLog); + } else { + XxlJobFileAppender.appendLog(logFileName, formatAppendLog); + logger.debug(">>>>>>>>>>> [{}]: {}", logFileName, formatAppendLog); + } } /** 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 cf1e985a..22503eac 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 @@ -92,6 +92,14 @@ public class JobThread extends Thread{ @Override public void run() { + // init + try { + handler.init(); + } catch (Throwable e) { + logger.error(e.getMessage(), e); + } + + // execute while(!toStop){ running = false; idleTimes++; @@ -165,6 +173,13 @@ public class JobThread extends Thread{ } } + // destroy + try { + handler.destroy(); + } catch (Throwable e) { + logger.error(e.getMessage(), e); + } + logger.info(">>>>>>>>>>> xxl-job JobThread stoped, hashCode:{}", Thread.currentThread()); } }