一、頁面上執(zhí)行一次
先通過前端頁面的按鈕, 找到對應(yīng)后端的接口;
找到源碼中對應(yīng)的controller
//這個方法
com.oppo.dispatchcenter.controller.JobInfoController.triggerJob
二圈匆、方法調(diào)用
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;
/**
這里根據(jù)minTim 與 minTim_now的分鐘值是否相等, 來判斷是否在同一分鐘執(zhí)行的
long minTim_now = System.currentTimeMillis() / 60000; 毫秒除以60000獲得分鐘, 因為返回為long, 同一分鐘值時相等的
不在同一分鐘清空超時計數(shù)器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
//真正執(zhí)行的方法
runResult = executorBiz.run(triggerParam);
->
com.xxl.job.core.biz.client.ExecutorBizClient#run
//調(diào)用執(zhí)行中心, 這里通過http請求去觸發(fā)執(zhí)行中心觸發(fā)