Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to create cron job in liferay

    • 0
    • 1
    • 0
    • 1
    • 0
    • 0
    • 0
    • 0
    • 2.39k
    Comment on it

    Cron job is a UNIX tool, its scheduling capabilities are powerful and proven. The CronTrigger class of cron is based on the scheduling capabilities.

     

    CronTrigger uses “cron expressions”, which are able to create firing schedules such as: “At 8:00am every Monday through Friday”

     

    Follow the below steps to create cron job in liferay :

    Step 1: Create a Scheduler class and put below code :

    package com.bhagwan;
    
    import com.liferay.portal.kernel.messaging.Message;
    import com.liferay.portal.kernel.messaging.MessageListener;
    import com.liferay.portal.kernel.messaging.MessageListenerException;
    
    public class CronJobListener implements MessageListener {
    
       @Override
       public void receive(Message message) throws MessageListenerException {
          //Here is the buisness logic to be written as per your requirement
          System.out.println("schedulerunning...");
       }
    }

     

    Step 2: Specify the scheduler class in the liferay-portlet.xml

    <scheduler-entry>
       <scheduler-description>
          This scheduler is used to run my own job
       </scheduler-description>
       <scheduler-event-listener-class>
          com.bhagwan.CronJobListener
       </scheduler-event-listener-class>
       <trigger>
          <simple>
             <simple-trigger-value>1</simple-trigger-value>
          <!-- <property-key></property-key> -->
          <time-unit>minute</time-unit>
          </simple>
          <!--
          <cron>
             <cron-trigger-value>0 0 0 * * ?</cron-trigger-value>
          </cron>
          -->
       </trigger>
    </scheduler-entry>

     

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: