9/04/2014

How to start a liferay scheduled job programmatically

You can start liferay scheduled jobs via configuration in the liferay-portlet.xml file (see here) and you can stop them programmatically (see here).  And this is how you start them:

public static void startProcess(String name, String portletId) {
  SchedulerEntry schedulerEntry = new SchedulerEntryImpl();
  schedulerEntry.setDescription("This is a programatically created process");
  schedulerEntry.setEventListenerClass(Your-Listener-Class.class.getName());
  schedulerEntry.setTimeUnit(TimeUnit.MINUTE);
  schedulerEntry.setTriggerType(TriggerType.SIMPLE);
  schedulerEntry.setTriggerValue(30);

 try {
   SchedulerPropertiesLocalServiceUtil.turnOnProcess(Your-Listener-Class.getName());
   SchedulerEngineHelperUtil.schedule(schedulerEntry, StorageType.MEMORY_CLUSTERED,
 portletId, 0);
 } catch (SchedulerException e) {

   _log.warn(e);
 }
 }


If you like this tutorial it would be very nice, if you could click on some of the google ads you see on the right side. It helps me run this block and motivates me ;)

If you have any questions, feel free to leave a comment.