scheduled task
Resin's <resin:ScheduledTask> capability lets you schedule
events using a flexible cron-style trigger. The task can be
any <resin:ScheduledTask> schedules a job to be executed at specific times
or after specific delays. The times can be specified by a cron syntax or
by a simple delay parameter. The job can be either a When specified as an Java Injection bean, the bean task has full IoC capabilities, including injection, @TransactionAttribute aspects, interception and @Observes.
Java Injection bean job configurationThe most common and flexible job configuration uses standard IoC
bean-style configuration. The bean must implement <web-app xmlns="http://caucho.com/ns/resin" xmlns:resin="urn:java:com.caucho.resin"> <resin:ScheduledTask> <cron>*/5</cron> <task> <qa:MyTask xmlns:qa="urn:java:com.caucho.resin"/> </task> </ScheduledTask> </web-app> task reference job configurationThe task bean can also be passed to the <scheduled-task> using
a Resin-IoC EL reference. The name of the task bean would be defined
previously, either in a <bean> or <component> or picked up by classpath
scanning. Like the bean-style job configuration, the reference bean must
implement <web-app xmlns="http://caucho.com/ns/resin" xmlns:resin="urn:java:com.caucho.resin"> <resin:ScheduledTask task="#{taskBean}"> <cron>0 0 *</cron> </resin:ScheduledTask> </web-app> method reference job configuration<scheduled-task> can execute a method on a defined bean as the scheduler's task. The method is specified using EL reference syntax. At each trigger time, <scheduled-task> will invoke the EL method expression. In the following example, the task invokes <web-app xmlns="http://caucho.com/ns/resin" xmlns:resin="urn:java:com.caucho.resin" xmlns:qa="urn:java:qa"> <qa:MyBean> <Named>myBean</Named> </qa:MyBean> <resin:ScheduledTask method="#{myBean.myMethod}"> <resin:delay>10m</resin:delay> <resin:period>1h</resin:period> </resin:ScheduledTask> </web-app> url job configurationIn a <web-app>, the <scheduled-task> can invoke a servlet URL
at the trigger times. The task uses the servlet <web-app xmlns="http://caucho.com/ns/resin" xmlns:resin="urn:java:com.caucho.config"> <resin:ScheduledTask url="/cron.php"> <resin:cron>0 15 * * 0</resin:cron> </resin:ScheduledTask> </web-app> cron trigger syntaxSome ascii art from the wikipedia cron entry # +---------------- minute (0 - 59) # | +------------- hour (0 - 23) # | | +---------- day of month (1 - 31) # | | | +------- month (1 - 12) # | | | | +---- day of week (0 - 6) (Sunday=0 or 7) # | | | | | * * * * *
Each field specifies a range of times to be executed. The patterns allowed are:
The minutes field is always required, and the hours, days, and months fields are optional.
|