下面說線程azkaban.trigger.TriggerManager.TriggerScannerThread是如何運做的java
1)初始化web
stop in azkaban.trigger.TriggerManager$TriggerScannerThread.xxxapp
runwebapp
初始化的上下文是:ui
java.lang.Exceptionspa
at azkaban.trigger.TriggerManager$TriggerScannerThread.xxx(TriggerManager.java:187)線程
at azkaban.trigger.TriggerManager$TriggerScannerThread.<init>(Trigg日誌
Step completed: erManager.java:191)ip
at azkaban.trigger.TriggerManager.<init"thread=main", azkaban.trigger.TriggerManager$TriggerScannerThread.xxx(), line=188 bci=10ci
>(Tri188 }
ggerManager.java:67)
at azkaban.wemain[1] bapp.AzkabanWebServer.loadTriggerManager(AzkabanWebServer.java:275)
at azkaban.webapp.AzkabanWebServer.<init>(AzkabanWebServer.java:199)
at azkaban.webapp.AzkabanWebServer.main(AzkabanWebServer.java:723)
=======================================================================================
2)線程的具體運行
stop in azkaban.trigger.TriggerManager$TriggerScannerThread.run
stop in azkaban.trigger.TriggerManager$TriggerScannerThread.checkAllTriggers
stop in azkaban.trigger.TriggerManager$TriggerScannerThread.onTriggerTrigger
---另外要注意:
long scannerInterval = props.getLong("trigger.scan.interval", DEFAULT_SCANNER_INTERVAL_MS);
runnerThread = new TriggerScannerThread(scannerInterval);
設置了查看週期,默認值居然是
public static final long DEFAULT_SCANNER_INTERVAL_MS = 60000;
居然有1分鐘。。。
果真修改此值
而後繼續研究,發現
private void onTriggerTrigger(Trigger t) throws TriggerManagerException {
List<TriggerAction> actions = t.getTriggerActions();
for (TriggerAction action : actions) {
try {
logger.info("Doing trigger actions");
System.out.println("action*************************************:" + action);
action.doAction();//重點來了!!!
} catch (Exception e) {
logger.error("Failed to do action " + action.getDescription(), e);
} catch (Throwable th) {
logger.error("Failed to do action " + action.getDescription(), th);
}
}
if (t.isResetOnTrigger()) {
t.resetTriggerConditions();
t.resetExpireCondition();
} else {
t.setStatus(TriggerStatus.EXPIRED);
}
try {
triggerLoader.updateTrigger(t);
} catch (TriggerLoaderException e) {
throw new TriggerManagerException(e);
}
}
若是屏蔽這行,exec就不會執行任務!
action的代碼是azkaban.trigger.builtin.ExecuteFlowAction
============================================================
經過這裏加代碼觀察
而後觀察打印出來的日誌:
正好驗證了個人想法!由於個人任務也是6秒爲週期!
==================================================================================
stop in azkaban.trigger.builtin.ExecuteFlowAction.doAction
run
==================================================================================
總結:定時把一個任務放入到web的一個queue中,而一次性任務則是放置1次!