|
|
|
@ -3,9 +3,10 @@ package com.xxl.job.admin.business.scheduler.thread;
|
|
|
|
import com.xxl.job.admin.business.model.XxlJobGroup;
|
|
|
|
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.RegistType;
|
|
|
|
import com.xxl.job.core.constant.RegistType;
|
|
|
|
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.tool.concurrent.CyclicThread;
|
|
|
|
import com.xxl.tool.core.StringTool;
|
|
|
|
import com.xxl.tool.core.StringTool;
|
|
|
|
import com.xxl.tool.response.Response;
|
|
|
|
import com.xxl.tool.response.Response;
|
|
|
|
import org.slf4j.Logger;
|
|
|
|
import org.slf4j.Logger;
|
|
|
|
@ -20,20 +21,25 @@ import java.util.concurrent.*;
|
|
|
|
* @author xuxueli 2016-10-02 19:10:24
|
|
|
|
* @author xuxueli 2016-10-02 19:10:24
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public class JobRegistryHelper {
|
|
|
|
public class JobRegistryHelper {
|
|
|
|
private static Logger logger = LoggerFactory.getLogger(JobRegistryHelper.class);
|
|
|
|
private static final Logger logger = LoggerFactory.getLogger(JobRegistryHelper.class);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* registry or remove thread pool
|
|
|
|
|
|
|
|
*/
|
|
|
|
private ThreadPoolExecutor registryOrRemoveThreadPool = null;
|
|
|
|
private ThreadPoolExecutor registryOrRemoveThreadPool = null;
|
|
|
|
private Thread registryMonitorThread;
|
|
|
|
|
|
|
|
private volatile boolean toStop = false;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* registry monitor thread
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
private CyclicThread registryMonitorThread;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* start
|
|
|
|
* start
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public void start(){
|
|
|
|
public void start(){
|
|
|
|
|
|
|
|
|
|
|
|
// for registry or remove
|
|
|
|
// 1、for registry or remove
|
|
|
|
registryOrRemoveThreadPool = new ThreadPoolExecutor(
|
|
|
|
registryOrRemoveThreadPool = new ThreadPoolExecutor(
|
|
|
|
2,
|
|
|
|
2,
|
|
|
|
10,
|
|
|
|
10,
|
|
|
|
@ -54,12 +60,10 @@ public class JobRegistryHelper {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
// for monitor
|
|
|
|
// 2、for registry monitor
|
|
|
|
registryMonitorThread = new Thread(new Runnable() {
|
|
|
|
registryMonitorThread = new CyclicThread("JobRegistryHelper#registryMonitorThread", true, new Runnable() {
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
public void run() {
|
|
|
|
while (!toStop) {
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
// auto registry group
|
|
|
|
// auto registry group
|
|
|
|
List<XxlJobGroup> groupList = XxlJobAdminBootstrap.getInstance().getXxlJobGroupMapper().findByAddressType(0);
|
|
|
|
List<XxlJobGroup> groupList = XxlJobAdminBootstrap.getInstance().getXxlJobGroupMapper().findByAddressType(0);
|
|
|
|
if (groupList!=null && !groupList.isEmpty()) {
|
|
|
|
if (groupList!=null && !groupList.isEmpty()) {
|
|
|
|
@ -109,24 +113,8 @@ public class JobRegistryHelper {
|
|
|
|
XxlJobAdminBootstrap.getInstance().getXxlJobGroupMapper().update(group);
|
|
|
|
XxlJobAdminBootstrap.getInstance().getXxlJobGroupMapper().update(group);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} catch (Throwable e) {
|
|
|
|
|
|
|
|
if (!toStop) {
|
|
|
|
|
|
|
|
logger.error(">>>>>>>>>>> xxl-job, job registry monitor thread error:{}", e);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
try {
|
|
|
|
}, Const.BEAT_TIMEOUT * 1000L, true);
|
|
|
|
TimeUnit.SECONDS.sleep(Const.BEAT_TIMEOUT);
|
|
|
|
|
|
|
|
} catch (Throwable e) {
|
|
|
|
|
|
|
|
if (!toStop) {
|
|
|
|
|
|
|
|
logger.error(">>>>>>>>>>> xxl-job, job registry monitor thread error:{}", e);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
logger.info(">>>>>>>>>>> xxl-job, job registry monitor thread stop");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
registryMonitorThread.setDaemon(true);
|
|
|
|
|
|
|
|
registryMonitorThread.setName("xxl-job, admin JobRegistryMonitorHelper-registryMonitorThread");
|
|
|
|
|
|
|
|
registryMonitorThread.start();
|
|
|
|
registryMonitorThread.start();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@ -135,18 +123,12 @@ public class JobRegistryHelper {
|
|
|
|
* stop
|
|
|
|
* stop
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public void stop(){
|
|
|
|
public void stop(){
|
|
|
|
toStop = true;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// stop registryOrRemoveThreadPool
|
|
|
|
// 1、registryOrRemoveThreadPool
|
|
|
|
registryOrRemoveThreadPool.shutdownNow();
|
|
|
|
registryOrRemoveThreadPool.shutdownNow();
|
|
|
|
|
|
|
|
|
|
|
|
// stop monitor (interrupt and wait)
|
|
|
|
// 2、registryMonitorThread
|
|
|
|
registryMonitorThread.interrupt();
|
|
|
|
registryMonitorThread.stop();
|
|
|
|
try {
|
|
|
|
|
|
|
|
registryMonitorThread.join();
|
|
|
|
|
|
|
|
} catch (Throwable e) {
|
|
|
|
|
|
|
|
logger.error(e.getMessage(), e);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|