在工作流程引擎中使用Quartz

來源:互聯網
上載者:User

在osworkflow中,Trigger Function是通過Quartz來實現的,我們看看
LocalWorkflowJob.java的實現代碼:
public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
        //JobDataMap是在schedule開始前放入的
        JobDataMap data = jobExecutionContext.getJobDetail().getJobDataMap();
        //entryId是工作流程執行個體號
        long id = data.getLong("entryId");
        //在流程定義中定義的trigger的id
        int triggerId = data.getInt("triggerId");
        String username = data.getString("username");
        Workflow wf = new BasicWorkflow(username);
        try {
            //執行真正的trigger
            wf.executeTriggerFunction(id, triggerId);
        } catch (WorkflowException e) {
            //this cast is a fairly horrible hack, but it's more due to the fact that quartz is stupid enough to have wrapped exceptions
            //wrap Exception, instead of Throwable.
            throw new JobExecutionException("Error Executing local job", (e.getRootCause() != null) ? (Exception) e.getRootCause() : e, true);
        }
    }

其實,我們在自己的工作流程引擎或者系統中,還可以用Quartz實現更多的功能.
比如,我們有需求是要為流程或者活動指定時間限制,到該時間限制前10分鐘
要向任務執行者警示,那麼我們可以這樣實現:
在伺服器啟動時啟動scheduler,然後每1分鐘,計算引擎中的流程執行個體還剩下的
時間,這個時間不需要持久化,直接記錄在記憶體中,可以由引擎的其它部分讀取.

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.