1 / 11

CS520 Web Programming Task Scheduling

CS520 Web Programming Task Scheduling. Chengyu Sun California State University, Los Angeles. Scheduled Tasks. Daily or weekly email digest Offline processing Index optimization Topic clustering Service reminders …. Java Timer and TimerTask. public class TimerTest {

ptrice
Download Presentation

CS520 Web Programming Task Scheduling

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. CS520 Web ProgrammingTask Scheduling Chengyu Sun California State University, Los Angeles

  2. Scheduled Tasks • Daily or weekly email digest • Offline processing • Index optimization • Topic clustering • Service reminders • …

  3. Java Timer and TimerTask public class TimerTest { public static void main( String args[] ) { new Timer().schedule( new ScheduledTask(), 5000, 2000 ); System.out.println( "task scheduled" ); } } class ScheduledTask extends TimerTask { public void run() { System.out.println( "hello" ); } }

  4. TimerTask Scheduling • Execute Once • schedule(TimerTask task, Date time) • schedule(TimerTask task, long delay) • Execute periodically • schedule(TimerTask task, Date firstTime, long period) • schedule(TimerTask task, long delay, long period)

  5. Spring Support for TimerTask <bean id=“someScheduledTask" class="org.springframework.scheduling.timer.ScheduledTimerTask"> <property name="timerTask"> <ref bean=“someTimerTask"/> </property> <property name="delay"> <value>3600000</value> </property> <property name="period"> <value>86400000</value> </property> </bean>

  6. Quartz • http://www.opensymphony.com/quartz/ • Triggers • Simple triggers • Cron triggers • Jobs • Execution • Persistence • … and more

  7. Cron Expression • Seven field separated by space • Seconds (0-59) • Minutes (0-59) • Hours (0-23) • Day of month (1-31) • Month (1-12 or JAN-DEC) • Day of week (1-7 or MON-SUN) • Year (1970-2099) [optional]

  8. Cron Field Values • Single value, e.g. 12 • Set of values, e.g. 0,15,30,45 • Range, e.g. 1-12 • * • Day of month and day of week are mutually exclusive, so one of them should be ?

  9. Cron Expression Examples 0 0 10,14,16 * * ? 0 0,15,30,45 * 1-10 * ? 30 0 0 1 1 ? 2012 0 0 8-5 ? * MON-FRI

  10. Spring Support for Quartz • Job • QuartzJobBean • Single method invocation • Trigger • Simple trigger using start time and repeat interval (optional) • Cron trigger using cron expression • Schedule • SchedulerFactoryBean

  11. Evelyn Example • CheckUsersJob • IndexOptimizationJob

More Related