Sometimes it is needed to create a task that is being executed periodically. We can use scheduler (based on Quartz API ) that is integrated with Liferay. There are 3 steps to do this.
1. Write a class the implements the com.liferay.portal.job.Scheduler interface
2. Write a class that contains actual task that needs to be executed. This class must implements com.liferay.portal.job.IntervalJob interface
3. Register your scheduler in liferay-portlet-ext.xml ( if you use ext environment )
Now let’s go to the details.
1. Write a class that implements Scheduler interface.
2. Write the class that contains actual task. On this example, our actual task would be only to write ‘THIS IS THE ACTUAL TASK!” to console. This task would be executed every minute.
If you want to change the interval, you can just change this line :
Change Time.MINUTE to Time.HOUR or Time.DAY.
3. Register in liferay-portlet-ext.xml.