JEE6 Schedulers

Creating a scheduler in JEE6 is very simple. Just use @Schedule annotation. Here is an example of a simple bean logging all 30 seconds.

import javax.ejb.Schedule;
import javax.ejb.Stateless;
import javax.inject.Inject;

import org.jboss.logging.Logger;

/**
    * @author manuel
    *
    */
@Stateless
public class ApplicationScheduler {

             @Inject
             private Logger log;

             /**
              * Do something when fired. @Schedule can handle cron syntax. Default
              * values:
              * <ul>
              * <li>hour=0</li>
              * <li>minute=0</li>
              * <li>second=0</li>
              * <li>dayOfMonth=*</li>
              * <li>month=*</li>
              * <li>dayOfWeek=*</li>
              * <li>year=*</li>
              * <li>timezone="" - uses container tz if not specified here; column TZ of
              * http://en.wikipedia.org/wiki/List_of_tz_database_time_zones</li>
              * <li>info=""</li>
              * <li>persistent=true</li>
              * </ul>
              */
             @Schedule(hour = "*", minute = "*", second = "*/30", persistent = false,
       timezone = "Europe/Vienna", info = "some info about this timer")
             public void backgroundProcessing() {
                          log.debug("some background work");
             }
}

Leave a Comment