refactor(core): 重构注册类型枚举并优化代码结构

- 将 RegistType 重命名为 RegistTypeEnum 并更新所有引用
- 为 ExecutorBlockStrategyEnum 添加详细的 JavaDoc 注释
- 为 XxlJobContext 类的常量添加完整的注释文档
- 在 XxlJobHelper 中完善方法注释
- 优化 XxlJobExecutor 启动方法的日志描述
- 在 SpringGlueFactory 中改进字符串判空逻辑
- 为多个核心类的字段添加 final 修饰符增强安全性
- 完善 OpenAPI 接口的方法参数注释
- 优化线程停止逻辑,添加空指针检查避免异常
- 修复重复触发作业的日志消息拼写错误
- 改进队列状态检查方法的性能表现
3.4.1-release
xuxueli 3 months ago
parent 9d4ba92537
commit f4487acdfc

@ -8,7 +8,7 @@ import com.xxl.job.admin.business.mapper.XxlJobGroupMapper;
import com.xxl.job.admin.business.mapper.XxlJobInfoMapper; import com.xxl.job.admin.business.mapper.XxlJobInfoMapper;
import com.xxl.job.admin.business.mapper.XxlJobRegistryMapper; import com.xxl.job.admin.business.mapper.XxlJobRegistryMapper;
import com.xxl.job.core.constant.Const; import com.xxl.job.core.constant.Const;
import com.xxl.job.core.constant.RegistType; import com.xxl.job.core.constant.RegistTypeEnum;
import com.xxl.sso.core.annotation.XxlSso; import com.xxl.sso.core.annotation.XxlSso;
import com.xxl.tool.core.CollectionTool; import com.xxl.tool.core.CollectionTool;
import com.xxl.tool.core.StringTool; import com.xxl.tool.core.StringTool;
@ -164,7 +164,7 @@ public class JobGroupController {
List<XxlJobRegistry> list = xxlJobRegistryMapper.findAll(Const.DEAD_TIMEOUT, new Date()); List<XxlJobRegistry> list = xxlJobRegistryMapper.findAll(Const.DEAD_TIMEOUT, new Date());
if (CollectionTool.isNotEmpty(list)) { if (CollectionTool.isNotEmpty(list)) {
for (XxlJobRegistry item: list) { for (XxlJobRegistry item: list) {
if (!RegistType.EXECUTOR.name().equals(item.getRegistryGroup())) { if (!RegistTypeEnum.EXECUTOR.name().equals(item.getRegistryGroup())) {
continue; continue;
} }
@ -211,7 +211,7 @@ public class JobGroupController {
// remove group // remove group
int ret = xxlJobGroupMapper.remove(id); int ret = xxlJobGroupMapper.remove(id);
// remove registry-data // remove registry-data
xxlJobRegistryMapper.removeByRegistryGroupAndKey(RegistType.EXECUTOR.name(), xxlJobGroup.getAppname()); xxlJobRegistryMapper.removeByRegistryGroupAndKey(RegistTypeEnum.EXECUTOR.name(), xxlJobGroup.getAppname());
return (ret>0)?Response.ofSuccess():Response.ofFail(); return (ret>0)?Response.ofSuccess():Response.ofFail();
} }

@ -4,7 +4,7 @@ import com.xxl.job.admin.business.model.XxlJobGroup;
import com.xxl.job.admin.business.model.XxlJobRegistry; import com.xxl.job.admin.business.model.XxlJobRegistry;
import com.xxl.job.admin.business.scheduler.config.XxlJobAdminBootstrap; import com.xxl.job.admin.business.scheduler.config.XxlJobAdminBootstrap;
import com.xxl.job.core.constant.Const; import com.xxl.job.core.constant.Const;
import com.xxl.job.core.constant.RegistType; import com.xxl.job.core.constant.RegistTypeEnum;
import com.xxl.job.core.openapi.model.RegistryRequest; import com.xxl.job.core.openapi.model.RegistryRequest;
import com.xxl.tool.concurrent.CyclicThread; import com.xxl.tool.concurrent.CyclicThread;
import com.xxl.tool.core.StringTool; import com.xxl.tool.core.StringTool;
@ -79,7 +79,7 @@ public class JobRegistryHelper {
List<XxlJobRegistry> list = XxlJobAdminBootstrap.getInstance().getXxlJobRegistryMapper().findAll(Const.DEAD_TIMEOUT, new Date()); List<XxlJobRegistry> list = XxlJobAdminBootstrap.getInstance().getXxlJobRegistryMapper().findAll(Const.DEAD_TIMEOUT, new Date());
if (list != null) { if (list != null) {
for (XxlJobRegistry item: list) { for (XxlJobRegistry item: list) {
if (RegistType.EXECUTOR.name().equals(item.getRegistryGroup())) { if (RegistTypeEnum.EXECUTOR.name().equals(item.getRegistryGroup())) {
String appname = item.getRegistryKey(); String appname = item.getRegistryKey();
List<String> registryList = appAddressMap.get(appname); List<String> registryList = appAddressMap.get(appname);
if (registryList == null) { if (registryList == null) {

@ -1,7 +1,7 @@
package com.xxl.job.admin.business.mapper; package com.xxl.job.admin.business.mapper;
import com.xxl.job.admin.business.model.XxlJobRegistry; import com.xxl.job.admin.business.model.XxlJobRegistry;
import com.xxl.job.core.constant.RegistType; import com.xxl.job.core.constant.RegistTypeEnum;
import jakarta.annotation.Resource; import jakarta.annotation.Resource;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.SpringBootTest;
@ -19,7 +19,7 @@ public class XxlJobRegistryMapperTest {
@Test @Test
public void test(){ public void test(){
int ret = xxlJobRegistryMapper.registrySaveOrUpdate(RegistType.EXECUTOR.name(), "xxl-job-executor-z1", "v1", new Date()); int ret = xxlJobRegistryMapper.registrySaveOrUpdate(RegistTypeEnum.EXECUTOR.name(), "xxl-job-executor-z1", "v1", new Date());
/*int ret = xxlJobRegistryDao.registryUpdate("g1", "k1", "v1", new Date()); /*int ret = xxlJobRegistryDao.registryUpdate("g1", "k1", "v1", new Date());
if (ret < 1) { if (ret < 1) {
ret = xxlJobRegistryDao.registrySave("g1", "k1", "v1", new Date()); ret = xxlJobRegistryDao.registrySave("g1", "k1", "v1", new Date());

@ -1,6 +1,6 @@
package com.xxl.job.openapi; package com.xxl.job.openapi;
import com.xxl.job.core.constant.RegistType; import com.xxl.job.core.constant.RegistTypeEnum;
import com.xxl.job.core.openapi.AdminBiz; import com.xxl.job.core.openapi.AdminBiz;
import com.xxl.job.core.openapi.model.CallbackRequest; import com.xxl.job.core.openapi.model.CallbackRequest;
import com.xxl.job.core.openapi.model.RegistryRequest; import com.xxl.job.core.openapi.model.RegistryRequest;
@ -61,7 +61,7 @@ public class AdminBizTest {
public void registry() throws Exception { public void registry() throws Exception {
AdminBiz adminBiz = buildClient(); AdminBiz adminBiz = buildClient();
RegistryRequest registryParam = new RegistryRequest(RegistType.EXECUTOR.name(), "xxl-job-executor-example", "127.0.0.1:9999"); RegistryRequest registryParam = new RegistryRequest(RegistTypeEnum.EXECUTOR.name(), "xxl-job-executor-example", "127.0.0.1:9999");
Response<String> returnT = adminBiz.registry(registryParam); Response<String> returnT = adminBiz.registry(registryParam);
assertTrue(returnT.isSuccess()); assertTrue(returnT.isSuccess());
@ -76,7 +76,7 @@ public class AdminBizTest {
public void registryRemove() throws Exception { public void registryRemove() throws Exception {
AdminBiz adminBiz = buildClient(); AdminBiz adminBiz = buildClient();
RegistryRequest registryParam = new RegistryRequest(RegistType.EXECUTOR.name(), "xxl-job-executor-example", "127.0.0.1:9999"); RegistryRequest registryParam = new RegistryRequest(RegistTypeEnum.EXECUTOR.name(), "xxl-job-executor-example", "127.0.0.1:9999");
Response<String> returnT = adminBiz.registryRemove(registryParam); Response<String> returnT = adminBiz.registryRemove(registryParam);
assertTrue(returnT.isSuccess()); assertTrue(returnT.isSuccess());

@ -5,13 +5,30 @@ package com.xxl.job.core.constant;
*/ */
public enum ExecutorBlockStrategyEnum { public enum ExecutorBlockStrategyEnum {
/**
* serial execution
*/
SERIAL_EXECUTION("Serial execution"), SERIAL_EXECUTION("Serial execution"),
/**
* concurrent execution
*/
/*CONCURRENT_EXECUTION("并行"),*/ /*CONCURRENT_EXECUTION("并行"),*/
/**
* discard later
*/
DISCARD_LATER("Discard Later"), DISCARD_LATER("Discard Later"),
/**
* cover early
*/
COVER_EARLY("Cover Early"); COVER_EARLY("Cover Early");
private String title; private String title;
private ExecutorBlockStrategyEnum (String title) { ExecutorBlockStrategyEnum (String title) {
this.title = title; this.title = title;
} }
@ -22,6 +39,13 @@ public enum ExecutorBlockStrategyEnum {
return title; return title;
} }
/**
* match by name
*
* @param name enum name
* @param defaultItem default item
* @return match item
*/
public static ExecutorBlockStrategyEnum match(String name, ExecutorBlockStrategyEnum defaultItem) { public static ExecutorBlockStrategyEnum match(String name, ExecutorBlockStrategyEnum defaultItem) {
if (name != null) { if (name != null) {
for (ExecutorBlockStrategyEnum item:ExecutorBlockStrategyEnum.values()) { for (ExecutorBlockStrategyEnum item:ExecutorBlockStrategyEnum.values()) {

@ -3,7 +3,7 @@ package com.xxl.job.core.constant;
/** /**
* Created by xuxueli on 17/5/9. * Created by xuxueli on 17/5/9.
*/ */
public enum RegistType{ public enum RegistTypeEnum {
/** /**
* executor registry * executor registry

@ -8,10 +8,22 @@ package com.xxl.job.core.context;
*/ */
public class XxlJobContext { public class XxlJobContext {
/**
* handle success
*/
public static final int HANDLE_CODE_SUCCESS = 200; public static final int HANDLE_CODE_SUCCESS = 200;
/**
* handle fail
*/
public static final int HANDLE_CODE_FAIL = 500; public static final int HANDLE_CODE_FAIL = 500;
/**
* handle timeout
*/
public static final int HANDLE_CODE_TIMEOUT = 502; public static final int HANDLE_CODE_TIMEOUT = 502;
// ---------------------- base info ---------------------- // ---------------------- base info ----------------------
/** /**
@ -24,6 +36,7 @@ public class XxlJobContext {
*/ */
private final String jobParam; private final String jobParam;
// ---------------------- for log ---------------------- // ---------------------- for log ----------------------
/** /**
@ -41,6 +54,7 @@ public class XxlJobContext {
*/ */
private final String logFileName; private final String logFileName;
// ---------------------- for shard ---------------------- // ---------------------- for shard ----------------------
/** /**
@ -53,6 +67,7 @@ public class XxlJobContext {
*/ */
private final int shardTotal; private final int shardTotal;
// ---------------------- for handle ---------------------- // ---------------------- for handle ----------------------
/** /**
@ -133,6 +148,7 @@ public class XxlJobContext {
return handleMsg; return handleMsg;
} }
// ---------------------- tool ---------------------- // ---------------------- tool ----------------------
/** /**

@ -256,6 +256,8 @@ public class XxlJobHelper {
} }
/** /**
* handle result
*
* @param handleCode * @param handleCode
* *
* 200 : success * 200 : success

@ -117,7 +117,7 @@ public class XxlJobExecutor {
*/ */
public void start() throws Exception { public void start() throws Exception {
// init instance // bind instance
xxlJobExecutor = this; xxlJobExecutor = this;
// valid enabled // valid enabled

@ -2,6 +2,7 @@ package com.xxl.job.core.glue;
import com.xxl.job.core.glue.impl.SpringGlueFactory; import com.xxl.job.core.glue.impl.SpringGlueFactory;
import com.xxl.job.core.handler.IJobHandler; import com.xxl.job.core.handler.IJobHandler;
import com.xxl.tool.core.StringTool;
import groovy.lang.GroovyClassLoader; import groovy.lang.GroovyClassLoader;
import java.math.BigInteger; import java.math.BigInteger;
@ -39,22 +40,20 @@ public class GlueFactory {
/** /**
* groovy class loader * groovy class loader
*/ */
private GroovyClassLoader groovyClassLoader = new GroovyClassLoader(); private final GroovyClassLoader groovyClassLoader = new GroovyClassLoader();
private ConcurrentMap<String, Class<?>> CLASS_CACHE = new ConcurrentHashMap<>(); private final ConcurrentMap<String, Class<?>> CLASS_CACHE = new ConcurrentHashMap<>();
/** /**
* load new instance, prototype * load new instance, prototype
* *
* @param codeSource * @param codeSource code source
* @return * @return IJobHandler
* @throws Exception
*/ */
public IJobHandler loadNewInstance(String codeSource) throws Exception{ public IJobHandler loadNewInstance(String codeSource) throws Exception{
if (codeSource!=null && codeSource.trim().length()>0) { if (StringTool.isNotBlank(codeSource)) {
Class<?> clazz = getCodeSourceClass(codeSource); Class<?> clazz = getCodeSourceClass(codeSource);
if (clazz != null) { if (clazz != null) {
Object instance = clazz.newInstance(); Object instance = clazz.newInstance();
if (instance!=null) {
if (instance instanceof IJobHandler) { if (instance instanceof IJobHandler) {
this.injectService(instance); this.injectService(instance);
return (IJobHandler) instance; return (IJobHandler) instance;
@ -64,7 +63,6 @@ public class GlueFactory {
} }
} }
} }
}
throw new IllegalArgumentException(">>>>>>>>>>> xxl-glue, loadNewInstance error, instance is null"); throw new IllegalArgumentException(">>>>>>>>>>> xxl-glue, loadNewInstance error, instance is null");
} }
private Class<?> getCodeSourceClass(String codeSource){ private Class<?> getCodeSourceClass(String codeSource){
@ -87,7 +85,7 @@ public class GlueFactory {
/** /**
* inject service of bean field * inject service of bean field
* *
* @param instance * @param instance instance
*/ */
public void injectService(Object instance) { public void injectService(Object instance) {
// do something // do something

@ -2,6 +2,7 @@ package com.xxl.job.core.glue.impl;
import com.xxl.job.core.executor.impl.XxlJobSpringExecutor; import com.xxl.job.core.executor.impl.XxlJobSpringExecutor;
import com.xxl.job.core.glue.GlueFactory; import com.xxl.job.core.glue.GlueFactory;
import com.xxl.tool.core.StringTool;
import jakarta.annotation.Resource; import jakarta.annotation.Resource;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -16,12 +17,13 @@ import java.lang.reflect.Modifier;
* @author xuxueli 2018-11-01 * @author xuxueli 2018-11-01
*/ */
public class SpringGlueFactory extends GlueFactory { public class SpringGlueFactory extends GlueFactory {
private static Logger logger = LoggerFactory.getLogger(SpringGlueFactory.class); private static final Logger logger = LoggerFactory.getLogger(SpringGlueFactory.class);
/** /**
* inject action of spring * inject action of spring
* @param instance *
* @param instance instance
*/ */
@Override @Override
public void injectService(Object instance){ public void injectService(Object instance){
@ -40,24 +42,23 @@ public class SpringGlueFactory extends GlueFactory {
} }
Object fieldBean = null; Object fieldBean = null;
// with bean-id, bean could be found by both @Resource and @Autowired, or bean could only be found by @Autowired
// with bean-id, bean could be found by both @Resource and @Autowired, or bean could only be found by @Autowired
if (AnnotationUtils.getAnnotation(field, Resource.class) != null) { if (AnnotationUtils.getAnnotation(field, Resource.class) != null) {
try { try {
Resource resource = AnnotationUtils.getAnnotation(field, Resource.class); Resource resource = AnnotationUtils.getAnnotation(field, Resource.class);
if (resource.name()!=null && resource.name().length()>0){ if (resource!=null && StringTool.isNotBlank(resource.name())){
fieldBean = XxlJobSpringExecutor.getApplicationContext().getBean(resource.name()); fieldBean = XxlJobSpringExecutor.getApplicationContext().getBean(resource.name());
} else { } else {
fieldBean = XxlJobSpringExecutor.getApplicationContext().getBean(field.getName()); fieldBean = XxlJobSpringExecutor.getApplicationContext().getBean(field.getName());
} }
} catch (Exception e) { } catch (Exception e) {}
}
if (fieldBean==null ) { if (fieldBean==null ) {
fieldBean = XxlJobSpringExecutor.getApplicationContext().getBean(field.getType()); fieldBean = XxlJobSpringExecutor.getApplicationContext().getBean(field.getType());
} }
} else if (AnnotationUtils.getAnnotation(field, Autowired.class) != null) { } else if (AnnotationUtils.getAnnotation(field, Autowired.class) != null) {
Qualifier qualifier = AnnotationUtils.getAnnotation(field, Qualifier.class); Qualifier qualifier = AnnotationUtils.getAnnotation(field, Qualifier.class);
if (qualifier!=null && qualifier.value()!=null && qualifier.value().length()>0) { if (qualifier!=null && StringTool.isNotBlank(qualifier.value())) {
fieldBean = XxlJobSpringExecutor.getApplicationContext().getBean(qualifier.value()); fieldBean = XxlJobSpringExecutor.getApplicationContext().getBean(qualifier.value());
} else { } else {
fieldBean = XxlJobSpringExecutor.getApplicationContext().getBean(field.getType()); fieldBean = XxlJobSpringExecutor.getApplicationContext().getBean(field.getType());

@ -10,8 +10,6 @@ public abstract class IJobHandler {
/** /**
* execute handler, invoked when executor receives a scheduling request * execute handler, invoked when executor receives a scheduling request
*
* @throws Exception
*/ */
public abstract void execute() throws Exception; public abstract void execute() throws Exception;

@ -10,12 +10,21 @@ import com.xxl.job.core.handler.IJobHandler;
*/ */
public class GlueJobHandler extends IJobHandler { public class GlueJobHandler extends IJobHandler {
/**
* glue update time
*/
private long glueUpdatetime; private long glueUpdatetime;
/**
* job handler
*/
private IJobHandler jobHandler; private IJobHandler jobHandler;
public GlueJobHandler(IJobHandler jobHandler, long glueUpdatetime) { public GlueJobHandler(IJobHandler jobHandler, long glueUpdatetime) {
this.jobHandler = jobHandler; this.jobHandler = jobHandler;
this.glueUpdatetime = glueUpdatetime; this.glueUpdatetime = glueUpdatetime;
} }
public long getGlueUpdatetime() { public long getGlueUpdatetime() {
return glueUpdatetime; return glueUpdatetime;
} }
@ -23,7 +32,7 @@ public class GlueJobHandler extends IJobHandler {
@Override @Override
public void execute() throws Exception { public void execute() throws Exception {
XxlJobHelper.log("----------- glue.version:"+ glueUpdatetime +" -----------"); XxlJobHelper.log("----------- glue.version:"+ glueUpdatetime +" -----------");
jobHandler.execute(); this.jobHandler.execute();
} }
@Override @Override

@ -11,8 +11,8 @@ public class MethodJobHandler extends IJobHandler {
private final Object target; private final Object target;
private final Method method; private final Method method;
private Method initMethod; private final Method initMethod;
private Method destroyMethod; private final Method destroyMethod;
public MethodJobHandler(Object target, Method method, Method initMethod, Method destroyMethod) { public MethodJobHandler(Object target, Method method, Method initMethod, Method destroyMethod) {
this.target = target; this.target = target;
@ -50,4 +50,5 @@ public class MethodJobHandler extends IJobHandler {
public String toString() { public String toString() {
return super.toString()+"["+ target.getClass() + "#" + method.getName() +"]"; return super.toString()+"["+ target.getClass() + "#" + method.getName() +"]";
} }
} }

@ -14,10 +14,10 @@ import java.io.File;
*/ */
public class ScriptJobHandler extends IJobHandler { public class ScriptJobHandler extends IJobHandler {
private int jobId; private final int jobId;
private long glueUpdatetime; private final long glueUpdatetime;
private String gluesource; private final String gluesource;
private GlueTypeEnum glueType; private final GlueTypeEnum glueType;
public ScriptJobHandler(int jobId, long glueUpdatetime, String gluesource, GlueTypeEnum glueType){ public ScriptJobHandler(int jobId, long glueUpdatetime, String gluesource, GlueTypeEnum glueType){
this.jobId = jobId; this.jobId = jobId;

@ -17,8 +17,8 @@ public interface AdminBiz {
/** /**
* callback * callback
* *
* @param callbackRequestList * @param callbackRequestList callback request list
* @return * @return response
*/ */
public Response<String> callback(List<CallbackRequest> callbackRequestList); public Response<String> callback(List<CallbackRequest> callbackRequestList);
@ -28,16 +28,16 @@ public interface AdminBiz {
/** /**
* registry * registry
* *
* @param registryRequest * @param registryRequest registry request
* @return * @return response
*/ */
public Response<String> registry(RegistryRequest registryRequest); public Response<String> registry(RegistryRequest registryRequest);
/** /**
* registry remove * registry remove
* *
* @param registryRequest * @param registryRequest registry request
* @return * @return response
*/ */
public Response<String> registryRemove(RegistryRequest registryRequest); public Response<String> registryRemove(RegistryRequest registryRequest);

@ -10,6 +10,7 @@ public interface ExecutorBiz {
/** /**
* beat * beat
*
* @return response * @return response
*/ */
public Response<String> beat(); public Response<String> beat();
@ -24,6 +25,7 @@ public interface ExecutorBiz {
/** /**
* run * run
*
* @param triggerRequest triggerRequest * @param triggerRequest triggerRequest
* @return response * @return response
*/ */
@ -31,6 +33,7 @@ public interface ExecutorBiz {
/** /**
* kill * kill
*
* @param killRequest killRequest * @param killRequest killRequest
* @return response * @return response
*/ */
@ -38,6 +41,7 @@ public interface ExecutorBiz {
/** /**
* log * log
*
* @param logRequest logRequest * @param logRequest logRequest
* @return response * @return response
*/ */

@ -134,8 +134,8 @@ public class EmbedServer {
// ---------------------- registry ---------------------- // ---------------------- registry ----------------------
/** /**
* netty_http * netty_http server handler
* <p> *
* Copy from : https://github.com/xuxueli/xxl-rpc * Copy from : https://github.com/xuxueli/xxl-rpc
* *
* @author xuxueli 2015-11-24 22:25:15 * @author xuxueli 2015-11-24 22:25:15

@ -1,6 +1,6 @@
package com.xxl.job.core.thread; package com.xxl.job.core.thread;
import com.xxl.job.core.constant.RegistType; import com.xxl.job.core.constant.RegistTypeEnum;
import com.xxl.job.core.openapi.AdminBiz; import com.xxl.job.core.openapi.AdminBiz;
import com.xxl.job.core.openapi.model.RegistryRequest; import com.xxl.job.core.openapi.model.RegistryRequest;
import com.xxl.job.core.constant.Const; import com.xxl.job.core.constant.Const;
@ -48,7 +48,7 @@ public class ExecutorRegistryThreadHelper {
registryThread = new CyclicThread("ExecutorRegistryThread#registryThread", true, new Runnable() { registryThread = new CyclicThread("ExecutorRegistryThread#registryThread", true, new Runnable() {
@Override @Override
public void run() { public void run() {
RegistryRequest registryParam = new RegistryRequest(RegistType.EXECUTOR.name(), xxlJobExecutor.getAppname(), xxlJobExecutor.getAddress()); RegistryRequest registryParam = new RegistryRequest(RegistTypeEnum.EXECUTOR.name(), xxlJobExecutor.getAppname(), xxlJobExecutor.getAddress());
for (AdminBiz adminBiz: xxlJobExecutor.getAdminBizList()) { for (AdminBiz adminBiz: xxlJobExecutor.getAdminBizList()) {
try { try {
Response<String> registryResult = adminBiz.registry(registryParam); Response<String> registryResult = adminBiz.registry(registryParam);
@ -78,7 +78,9 @@ public class ExecutorRegistryThreadHelper {
/** /**
* 1stop registryThread * 1stop registryThread
*/ */
if (registryThread != null) {
registryThread.stop(); registryThread.stop();
}
/** /**
* 2registry remove * 2registry remove
@ -87,7 +89,7 @@ public class ExecutorRegistryThreadHelper {
} }
private void registryRemove(final XxlJobExecutor xxlJobExecutor){ private void registryRemove(final XxlJobExecutor xxlJobExecutor){
RegistryRequest registryParam = new RegistryRequest(RegistType.EXECUTOR.name(), xxlJobExecutor.getAppname(), xxlJobExecutor.getAddress()); RegistryRequest registryParam = new RegistryRequest(RegistTypeEnum.EXECUTOR.name(), xxlJobExecutor.getAppname(), xxlJobExecutor.getAddress());
for (AdminBiz adminBiz: xxlJobExecutor.getAdminBizList()) { for (AdminBiz adminBiz: xxlJobExecutor.getAdminBizList()) {
try { try {
Response<String> registryResult = adminBiz.registryRemove(registryParam); Response<String> registryResult = adminBiz.registryRemove(registryParam);

@ -102,7 +102,10 @@ public class JobLogFileCleanThreadHelper {
public void stop() { public void stop() {
// stop logFileCleanThread // stop logFileCleanThread
if (logFileCleanThread != null) {
logFileCleanThread.stop(); logFileCleanThread.stop();
} }
} }
}

@ -25,12 +25,12 @@ import java.util.concurrent.*;
public class JobThread extends Thread{ public class JobThread extends Thread{
private static final Logger logger = LoggerFactory.getLogger(JobThread.class); private static final Logger logger = LoggerFactory.getLogger(JobThread.class);
private int jobId; private final int jobId;
private IJobHandler handler; private final IJobHandler handler;
private LinkedBlockingQueue<TriggerRequest> triggerQueue; private final LinkedBlockingQueue<TriggerRequest> triggerQueue;
private Set<Long> triggerLogIdSet; // avoid repeat trigger for the same TRIGGER_LOG_ID private final Set<Long> triggerLogIdSet; // avoid repeat trigger for the same TRIGGER_LOG_ID
private volatile boolean toStop = false; private volatile boolean toStop = false; // thread stop flag
private String stopReason; private String stopReason;
private boolean running = false; // if running job private boolean running = false; // if running job
@ -41,8 +41,7 @@ public class JobThread extends Thread{
this.jobId = jobId; this.jobId = jobId;
this.handler = handler; this.handler = handler;
this.triggerQueue = new LinkedBlockingQueue<>(); this.triggerQueue = new LinkedBlockingQueue<>();
//this.triggerLogIdSet = Collections.synchronizedSet(new HashSet<Long>()); this.triggerLogIdSet = ConcurrentHashMap.newKeySet(); // Collections.synchronizedSet(new HashSet<Long>());
this.triggerLogIdSet = ConcurrentHashMap.newKeySet();
// assign job thread name // assign job thread name
this.setName("xxl-job, JobThread-"+jobId+"-"+System.currentTimeMillis()); this.setName("xxl-job, JobThread-"+jobId+"-"+System.currentTimeMillis());
@ -57,8 +56,8 @@ public class JobThread extends Thread{
public Response<String> pushTriggerQueue(TriggerRequest triggerParam) { public Response<String> pushTriggerQueue(TriggerRequest triggerParam) {
// avoid repeat // avoid repeat
if (!triggerLogIdSet.add(triggerParam.getLogId())) { if (!triggerLogIdSet.add(triggerParam.getLogId())) {
logger.info(">>>>>>>>>>> repeate trigger job, logId:{}", triggerParam.getLogId()); logger.info(">>>>>>>>>>> repeat trigger job, logId:{}", triggerParam.getLogId());
return Response.of(XxlJobContext.HANDLE_CODE_FAIL, "repeate trigger job, logId:" + triggerParam.getLogId()); return Response.of(XxlJobContext.HANDLE_CODE_FAIL, "repeat trigger job, logId:" + triggerParam.getLogId());
} }
// push trigger queue // push trigger queue
@ -83,20 +82,20 @@ public class JobThread extends Thread{
* is running job * is running job
*/ */
public boolean isRunningOrHasQueue() { public boolean isRunningOrHasQueue() {
return running || triggerQueue.size()>0; return running || !triggerQueue.isEmpty();
} }
@Override @Override
public void run() { public void run() {
// init // invoke init-method, only once
try { try {
handler.init(); handler.init();
} catch (Throwable e) { } catch (Throwable e) {
logger.error(e.getMessage(), e); logger.error(e.getMessage(), e);
} }
// execute // invoke job, listen schedule-center
while(!toStop){ while(!toStop){
running = false; running = false;
idleTimes++; idleTimes++;
@ -236,7 +235,7 @@ public class JobThread extends Thread{
} }
} }
// destroy // invoke destroy-method, only once
try { try {
handler.destroy(); handler.destroy();
} catch (Throwable e) { } catch (Throwable e) {

@ -71,7 +71,6 @@ public class TriggerCallbackThreadHelper {
1, 1,
50); 50);
/** /**
* 2retry callback-file thread * 2retry callback-file thread
*/ */
@ -130,8 +129,10 @@ public class TriggerCallbackThreadHelper {
} }
// 2、stop retryCallbackThread // 2、stop retryCallbackThread
if (callbackMessageQueue != null) {
retryCallbackThread.stop(); retryCallbackThread.stop();
} }
}
/** /**

Loading…
Cancel
Save