Scheduler in Liferay 7 /DXP, Isn’t it easy?

Often, there are requirements to automate certain process and execute it on regular interval. Scheduler programming helps for all such requirement. Liferay provides a flexible way to implement scheduler. In this post, I am going to talk about, steps to create scheduler in Liferay DXP/7.

Following are the prerequisite to start implementation,


Starting point to implement Scheduler in Liferay DXP/7 is to create module in Liferay workspace.

Create module in Liferay workspace:
To create Liferay modules, Right Click → New → Liferay Module Project. Give appropriate name and click finish.

You should see project structure as follow,

Now that you have created module in Liferay development environment, next step is to create class for scheduler. In this example I created class with name ‘LiferayScheduler’ under package com.enprowess.schedulerclass.

You need to extend BaseSchedulerEntryMessageListener class. This is abstract class contains default implementation for scheduler. You need to override two methods doReceive() and activate().

doReceive() : Implement the logic to execute on regular interval in this method. Ex,

protected void doReceive(Message message) throws Exception {"Add your business logic for schedule here…");

activate() : In this method you need to define schedule time to execute scheduler. Ex.

protected void activate() {
schedulerEntryImpl.setTrigger (
TriggerFactoryUtil.createTrigger(getEventListenerClass(), getEventListenerClass(), 24, TimeUnit.HOUR));
_schedulerEngineHelper.register(this, schedulerEntryImpl, DestinationNames.SCHEDULER_DISPATCH);

In above example, I am setting scheduler to execute on every 24 hours. Following are the method signatures of TriggerFactoryUtil to configure scheduler time interval,

  • 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)

I hope this post will give you fair idea how to implement scheduler in Liferay DXP/7. Happy coding!

Blog by,
Maitrik Panchal


Share it :

Leave a Reply

5 Comments on "Scheduler in Liferay 7 /DXP, Isn’t it easy?"

Notify of
Sort by:   newest | oldest
Seems to be a pretty good method, yet as someone new to Liferay I’d like further assistance. I’m using Liferay IDE, because Liferay Developer Studio is a payed software. I’m sure that their functionality is mostly the same. Now, when someone wants to create a module project, they are asked to select a template too, which by default is the MVC portlet template. As I couldn’t find an appropriate clean template, please let us know in-depth how to create the module project with the appropriate structure. Second and lastly I the examples you gave, but the variable _schedulerEngineHelper is nowhere… Read more »
gayu M
gayu M

How to mention my custom scheduler class in above method.

For an example in liferay 6.2 will create like this right.

Gasser Abdallah
Gasser Abdallah

Thanks, That was very helpful

  • Categories

  • Recent Comments

  • Recent Post

  • Tags