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)