Monday, April 29, 2013

Quartz with Spring 3.2


We can integrated popular scheduler Quarts with Spring 3.2 with Few Steps

1. Write your Java class targating to schedule

@Component
public class BoundryUnlimitedSchedule {
...
public void createReports() {
...............
.......
}
}

2. Configure the spring configuration file 
2.1 Add the scheduler class
       <!-- Quartz Scheduler Configurations -->
  <bean id="boundryUnlimitedSchedule"
    class="com.................BoundryUnlimitedSchedule" />
 
2.2. Add the defined schduler with Quartz
<bean id="methodJobDetailBean"
class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean"
p:concurrent="false" p:targetObject-ref="boundryUnlimitedSchedule"
p:targetMethod="createReports" />

2.3 Create the schedule
<bean id="cronTrigger" class="org.springframework.scheduling.quartz.CronTriggerBean" 
p:jobDetail-ref="methodJobDetailBean" 
p:startDelay="10000" 
p:cronExpression="0 0 8 ? * * *" />

3. More on cron expressions
        seconds | minutes  | hours |  daysOfMonth | months | daysOfWeek | years
 0            0           0          1                       *                ?           *          - 00:00:00 on every month on day 1
 0       10    23 L *          ?           *          - at 11:10 PM on the Last Day of the Month
 0        0     0         1W * ?           *  - first working day of each month at 00:00:00
 0             0          11         ?                       *               3           *          - every 3nd day of the week at 11:00 run this
 0            10          10         ?                       *              *           *          - every day at 10:10 run this