RE: Liferay Scheduler

Daniel G, modified 6 Years ago. Regular Member Posts: 141 Join Date: 3/14/17 Recent Posts
Hi all.

I am developing my first scheduler and I have some doubts regarding how to specify when it has to be executed. I want it to be launched once a day, at the same hour.

If I understood it correctly, I have to set activate method for it. I am able to specify that it is launched once a day, but I don't know how to specified the hour.
schedulerEntryImpl.setTrigger (
    TriggerFactoryUtil.createTrigger(getEventListenerClass(), getEventListenerClass(), 24, TimeUnit.HOUR));

I saw that setTrigger method has these definitions, but I don't know that is the "cronExpression" parameter.
  • createTrigger(String jobName, String groupName, Date startDate, Date endDate, int interval, TimeUnit timeUnit)
  • createTrigger(String jobName, String groupName, Date startDate, Date endDate, String cronExpression)
  • createTrigger(String jobName, String groupName, Date startDate, int interval, TimeUnit timeUnit)
  • createTrigger(String jobName, String groupName, Date startDate, String cronExpression)
  • createTrigger(String jobName, String groupName, int interval, TimeUnit timeUnit)
  • createTrigger(String jobName, String groupName, String cronExpression)

Any help would be appreciated.

Thanks in advance,

Kind regards
thumbnail
Fernando Fernandez, modified 6 Years ago. Expert Posts: 401 Join Date: 8/22/07 Recent Posts
Hi Daniel,

CronExpression is a string that defines when your task is run. It follows more or less the format of unix crontab and you can build with something it like this:

​​​​​​​String.format("%s %s %s %s %s ? %s", secs, mins, hrs, dom, mon, year)
​​​​​​​
You can use "*" instead of a number so a string like "0 0 0 * * * *" will run every day at midnight.

HTH

Fernando
thumbnail
Christoph Rabel, modified 6 Years ago. Liferay Legend Posts: 1555 Join Date: 9/24/09 Recent Posts
There are also some online cron builders available e.g.
http://www.cronmaker.com/

(First search hit for me, didn't really test it beyond a quick try)