How to run every 25 seconds in Quartz scheduler?

前端 未结 7 2257
悲哀的现实
悲哀的现实 2021-02-12 23:37

I am using the Quartz Scheduling API for Java. Could you help me to run every 25 seconds using cron-expression. It\'s just a delay. It does not have to start always at second 0.

相关标签:
7条回答
  • 2021-02-12 23:46
    */25 * * * * *
    


    - [wiki] http://en.wikipedia.org/wiki/Cron
    - [quartz tutorial] http://www.quartz-scheduler.org/docs/tutorial/TutorialLesson06.html

    0 讨论(0)
  • 2021-02-12 23:50

    The only way to do this with a cron trigger is so complicated as to be useless; you're much better off with the SimpleTrigger from other answers. Nevertheless, if it has to be cron, you need to set up five different cron triggers:

     0/25 0/5 * * * *
    15/25 1/5 * * * *
     5/25 2/5 * * * *
    20/25 3/5 * * * *
    10/25 4/5 * * * *
    

    The first trigger fires at 0:00:25, 0:00:50; then the second trigger fires at 0:01:15 and 0:01:40; the third at 0:02:05, 0:02:30, 0:02:55; the fourth at 0:03:20, 0:03:45; and finally the fifth at 0:04:10 and 0:04:35. The first trigger then takes over again at 0:05:00, etc.

    This only works because 25 seconds divides evenly into 5 minutes (which in turn goes evenly into an hour). If you wanted it every 23 seconds? Forget about it!

    0 讨论(0)
  • 2021-02-12 23:54

    You could schedule the job to run constantly but throttle the frequency using Camel's Throttler.

    <route>
      <from uri="jms:queue:TestQueue"/>
      <!-- throttle 1 messages per 25 sec -->
      <throttle timePeriodMillis="25000">
        <constant>1</constant>
        <to uri="bean:TestBean?method=testMethod"/>
      </throttle>
    </route>
    
    0 讨论(0)
  • 2021-02-12 23:58

    I don't think cron expression will allow you to do that, but you can use

    SimpleScheduleBuilder.repeatSecondlyForever( 25 )
    

    as 300 (5 minutes) is a multiple of 25 it will repeat automatically.

    0 讨论(0)
  • 2021-02-13 00:01

    If you want a job to trigger at a regular interval then you can use a Quartz SimpleTrigger with a repeatInterval specified.

    0 讨论(0)
  • 2021-02-13 00:04

    You can't have a schedule like that for quartz.

    One thing you could do is schedule a wrapper job to run every 5 seconds, and only do any work every fifth execution.

    0 讨论(0)
提交回复
热议问题