JobHandler提供init/destroy方法,支持在JobHandler初始化和销毁时进行附加操作;

master
xuxueli 7 years ago
parent 2d55c381c6
commit 2a94a142e3
  1. 9
      xxl-job-core/src/main/java/com/xxl/job/core/biz/impl/ExecutorBizImpl.java
  2. 15
      xxl-job-core/src/main/java/com/xxl/job/core/log/XxlJobLogger.java
  3. 15
      xxl-job-core/src/main/java/com/xxl/job/core/thread/JobThread.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<String>(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 &&

@ -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);
}
}
/**

@ -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());
}
}

Loading…
Cancel
Save