How do I declare a one-time simple trigger with the Quartz XML plugin?

ぐ巨炮叔叔 提交于 2019-12-23 10:58:08

问题


I'm trying to set up a job such that it runs once the first time my scheduler is started, then once at midnight every day after that. Here is my XML for the job and triggers. The once a day trigger works, but the one-time trigger does not.

    <job>
      <name>MyJob</name>
      <group>MyJobGroup</group>
      <job-type>MyScheduledJob, MyJobAssembly</job-type>
      <description>My job, yo</description>
      <durable>true</durable>
      <recover>false</recover>
    </job>
    <trigger>
      <cron>
        <name>MyTrigger</name>
        <group>MyTriggerGroup</group>
        <job-name>MyJob</job-name>
        <job-group>MyJobGroup</job-group>
        <cron-expression>0 0 0 1/1 * ? *</cron-expression>
      </cron>
        <simple>
            <name>MyOneTimeTrigger</name>
            <group>MyTriggerGroup</group>
            <description>Run once at startup, G</description>
            <misfire-instruction>SmartPolicy</misfire-instruction>
            <volatile>false</volatile>
            <job-name>MyJob</job-name>
            <job-group>MyJobGroup</job-group>
            <repeat-count>0</repeat-count>
            <repeat-interval>0</repeat-interval> 
      </simple>
    </trigger>

回答1:


By doesn't work I guess you mean the trigger never fires. Maybe because it has no delay it misfires? What about adding <start-time-seconds-in-future/> with some time in the future?

<simple>
        <name>MyOneTimeTrigger</name>
        <group>MyTriggerGroup</group>
        <description>Run once at startup, G</description>
        <misfire-instruction>SmartPolicy</misfire-instruction>
        <volatile>false</volatile>
        <job-name>MyJob</job-name>
        <job-group>MyJobGroup</job-group>
        <start-time-seconds-in-future>60</start-time-seconds-in-future>
        <repeat-count>0</repeat-count>
        <repeat-interval>0</repeat-interval> 
</simple>

If it works for you, you must be aware of something which you might consider either a bug or a feature: if you restart the server, because the trigger already fired and was removed, it will fire again. See: Quartz XML plugin reschedules fired triggers after restart.



来源:https://stackoverflow.com/questions/10687304/how-do-i-declare-a-one-time-simple-trigger-with-the-quartz-xml-plugin

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!