liferay quartz scheduler

Liferay Quartz Scheduler

liferay quartz scheduler tutorial will give you details on “How to configure quartz jobs in liferay?”. Liferay has out of the box support of Quartz Scheduler at portlet level and multiple CRON jobs can be configured for each portlet.

High Level Steps:

  •  Configure Cron Jobs for  portlet in liferay-portlet.xml
  • Provide scheduler-event-listener-class that implements com.liferay.portal.kernel.messaging.MessageListener and override below method
    1. @Override
       public void receive(Message arg0) throws MessageListenerException
  • sometimes, liferay cron will not run even  though nothing wrong in your implementation, but need to check what time zone server is running and change cron expression accordingly. By default, Liferay runs on  GMT time zone that can be found in file.

There are two ways you can configure  cron in liferay:

  1. Cron Expression
    • <scheduler-entry>
       <scheduler-description>Job at 10'c cloccl</scheduler-description>
       <cron-trigger-value>00 00 22 * * ? *</cron-trigger-value>
    • cron-trigger-value can be loaded from file like <cron-trigger-value>liferay.cron.job1</cron-trigger-value>
    • In file :
      • liferay.cron.job1=00 00 22 * * ? *
  2. Simple Cron:
    • Time unit: Valid values for this element are “day”,”hour”, “minute”, “second”, or “week”. The default value is “second”.
    • Simple-trigger-value is :  value
      1. <trigger>

Lets jump into tutorial:

Step1: Set Liferay Quartz Scheduler  Cron in liferay-portlet.xml

 <scheduler-description>Cron at 10 PM</scheduler-description>
            <cron-trigger-value>00 00 22 * * ? *</cron-trigger-value> 

Step2: Implement MessageListener class

In scheduler-event-listener-class, give, that implements  com.liferay.portal.kernel.messaging.MessageListener and as shown in below:

public class LiferayCronListener implements MessageListener{
 public void receive(Message arg0) throws MessageListenerException {" State Job Started at"+new Date());

Now deploy and you configured CRON.

Sample CRON Expressions:

  1. Job Runs daily at 11:45 PM
    1. <cron-trigger-value>0 45 23 1/1 * ? *</cron-trigger-value>
  2. Job Runs at every 10 minutes
    1.  <cron-trigger-value>0 0/10 1/1 1/1 * ? *</cron-trigger-value>
  3. Job Run for every two hours
    1.  <cron-trigger-value>0 0 0/2 1/1 * ? *</cron-trigger-value>

Hope this helps