Search code examples
crontimerschedulingquartz-schedulerjava-ee-5

Cron syntax with Java EE 5?


Timer Tasks in Java EE are not very comfortable. Is there any util, to configure timer with cron syntax like "0 20 20 * * "?

I wonder, if it would be a good way to use Quartzinside (clustered) Java EE application. According to http://www.prozesse-und-systeme.de/serverClustering.html (german page) there limits with Quartz and Java EE clustering:

  • JDBC must be used as job store for Quartz
  • Only cluster associated Quartz instances are allowed to use this JDBC job store
  • All cluster nodes must be synchronized to the split second
  • All cluster nodes must use the same quartz.properties file

I would prefer an easier way for configuration of timer service, instead an not Java EE managed scheduler.


Solution

  • Quartz definitely support cron-like syntax (with the CronTrigger) but your requirements are not clear. Also maybe have a look at Jcrontab or cron4j.


    As a side note, the ability to declaratively create cron-like schedules to trigger EJB methods is one of the most important enhancement of the Timer Service in EJB 3.1 (using the @Schedule annotation). Below, an example taken from New Features in EJB 3.1:

    @Stateless
    public class NewsLetterGeneratorBean implements NewsLetterGenerator {
    
        @Schedule(second="0", minute="0", hour="0",
                      dayOfMonth="1", month="*", year="*")
        public void generateMonthlyNewsLetter() {
            ... Code to generate the monthly news letter goes here...
        }
    }