一、页面上执行一次
先通过前端页面的按钮, 找到对应后端的接口;
找到源码中对应的controller
//这个方法
com.oppo.dispatchcenter.controller.JobInfoController.triggerJob
二、方法调用
JobTriggerPoolHelper.trigger(id, TriggerTypeEnum.MANUAL, -1, null, executorParam, addressList);
一直点下去找到该方法
//com.oppo.dispatchcenter.core.thread.JobTriggerPoolHelper#addTrigger
//源码如下
public void addTrigger(final int jobId,
final TriggerTypeEnum triggerType,
final int failRetryCount,
final String executorShardingParam,
final String executorParam,
final String addressList) {
// choose thread pool
/**
这里使用了两个线程池
1.fastTriggerPool 快线程
2.slowTriggerPool 慢线程
*/
ThreadPoolExecutor triggerPool_ = fastTriggerPool;
AtomicInteger jobTimeoutCount = jobTimeoutCountMap.get(jobId);
/**
进入该判断, 更换为慢线程池, 要去是1分钟超时十次的时候更换线程池
*/
if (jobTimeoutCount != null && jobTimeoutCount.get() > 10) { // job-timeout 10 times in 1 min
triggerPool_ = slowTriggerPool;
}
// trigger
/**
运行一个线程, 在finally 定义了上述说的更换慢线程条件
*/
triggerPool_.execute(new Runnable() {
@Override
public void run() {
long start = System.currentTimeMillis();
try {
// do trigger
XxlJobTrigger.trigger(jobId, triggerType, failRetryCount, executorShardingParam, executorParam, addressList);
} catch (Exception e) {
logger.error(e.getMessage(), e);
} finally {
// check timeout-count-map
long minTim_now = System.currentTimeMillis() / 60000;
/**
这里根据minTim 与 minTim_now的分钟值是否相等, 来判断是否在同一分钟执行的
long minTim_now = System.currentTimeMillis() / 60000; 毫秒除以60000获得分钟, 因为返回为long, 同一分钟值时相等的
不在同一分钟清空超时计数器jobTimeoutCountMap
*/
if (minTim != minTim_now) {
minTim = minTim_now;
jobTimeoutCountMap.clear();
}
// incr timeout-count-map
long cost = System.currentTimeMillis() - start;
if (cost > 500) { // ob-timeout threshold 500ms
AtomicInteger timeoutCount = jobTimeoutCountMap.putIfAbsent(jobId, new AtomicInteger(1));
if (timeoutCount != null) {
timeoutCount.incrementAndGet();
}
}
}
}
});
}
com.oppo.dispatchcenter.core.trigger.XxlJobTrigger#trigger
->
com.oppo.dispatchcenter.core.trigger.XxlJobTrigger#processTrigger
->
com.oppo.dispatchcenter.core.trigger.XxlJobTrigger#runExecutor
//真正执行的方法
runResult = executorBiz.run(triggerParam);
->
com.xxl.job.core.biz.client.ExecutorBizClient#run
//调用执行中心, 这里通过http请求去触发执行中心触发