Help

Built with Seam

You can find the full source code for this website in the Seam package in the directory /examples/wiki. It is licensed under the LGPL.

Some job schedules are static and can just be scheduled at start up time. Here is a simple way to do this.

@Name("myJobScheduler")
@Scope(ScopeType.APPLICATION)
@AutoCreate
@Startup
public class MyJobScheduler {

      @Logger
      private Log log;

      private String cron = "0/1 * * * * ?";

      private QuartzTriggerHandle handle;

      public void setCron(String cron) {
            this.cron = cron;
      }

      @Create
      public void schedule() throws Exception {
            handle = MyJob.instance().execute(cron);
		log.debug("Scheduled Job: #0 with: #1", handle.getTrigger().getName(),
				cron);
      }

      @Destroy
      public void unschedule() throws Exception {
            log.debug("Unscheduling Job: #0", handle.getTrigger().getName());
            handle.cancel();
      }

      @Name("myJob")
      @Scope(ScopeType.EVENT)
      @AutoCreate
      public static class MyJob {

            @Logger
            private Log log;

            @Asynchronous
            @Transactional
            public QuartzTriggerHandle execute(@IntervalCron String cron) {
                  log.info("Doing somthing...");
                  return null;
            }

            public static Job instance() {
                  return (Job) Component.getInstance(MyJob.class);
            }
      }
}