Any relation between Quartz API and Joda Time API?

2020-06-15 05:48发布

Is it possible to create a date in JodaTime and then make Quartz schedule the job using the JodaTime object? Can we give a Period jodaPeriod to Quartz API in order to run a task for a particular period in a day?

Are the two APIs related and/or compatible in any way?

4条回答
家丑人穷心不美
2楼-- · 2020-06-15 05:57

TriggerBuilder has a snippet of how to schedule a job by hand:

JobDetail job = newJob(MyJob.class)
         .withIdentity("myJob")
         .build();

Trigger trigger = newTrigger() 
         .withIdentity(triggerKey("myTrigger", "myTriggerGroup"))
         .withSchedule(simpleSchedule()
             .withIntervalInHours(1)
             .repeatForever())
         .startAt(futureDate(10, MINUTES))
         .build();

scheduler.scheduleJob(job, trigger);

You will have to do some conversion work for the startAt() and the withIntervalInHours()...you get the drift

查看更多
叛逆
3楼-- · 2020-06-15 06:06

The AxonFramework has a QuartzEventScheduler which looks like it does what you want.

Here's the downlaod page and it's under the Apache 2.0 license.

查看更多
神经病院院长
4楼-- · 2020-06-15 06:07

Quartz provides a pretty comprehensive API that you could extend anyway you wanted.
The hook you would need to create would be against the Trigger interface, I've created one before but not using Joda time.

From the sounds of your question if you want to create a job that runs for a particular period of the day you could also just try using the CronTrigger. For example to run every minute between 9am and 11am you could do

* 9-10 * * *

Obviously Joda makes it much easier to configure but your sysadmins respect you more for cron...

查看更多
手持菜刀,她持情操
5楼-- · 2020-06-15 06:09

I've started to use Joda Time in newer parts of my company's app and I've found it easier to link to the legacy parts (including Quartz scheduling) by converting the Joda Time object back to java.util.Date which the older parts are still expecting. I hope this helps.

查看更多
登录 后发表回答