9/04/2014

How to stop a liferay scheduler programmatically

As you know, liferay allows you to create schedulers to do repeatative tasks, like import or synchronization jobs.  If you don´t know that, then you might want to take a look here: Creating Liferay Scheduled Jobs .

Fot those of you who do know that it might be interesting to know how to forcefully stop such a started process programmatically. You never know when you need to stop the process.  This is how you do it :

try {
  scheduledJobs = SchedulerEngineHelperUtil.getScheduledJobs();
  for (SchedulerResponse resp : scheduledJobs) {
    if (resp.getJobName().equalsIgnoreCase(name)) {
      String groupName = resp.getGroupName();
      StorageType storageType = resp.getStorageType();
      _log.info("Unscheduling :" + name);
      SchedulerEngineHelperUtil.unschedule(name, groupName, storageType);
    }
 }
 } 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.