Liferay provides an easy way to implement scheduler. Scheduler is a very important aspect of software development these days. Using Liferay Scheduler we can automate certain processes and execute it on every specified time interval. i.e send an email after every day, send monthly newsletters, etc.

Prerequisites

  • JDK 8
  • Liferay portal 7/7.x

Assuming that you have already created a Liferay module project in eclipse IDE.

1) Create scheduler class

Here, you can specify your cron expression in ‘cron.expression’ property.
Cron expressions are based on the timezone of your server. You can learn more about corn expression here https://www.freeformatter.com/cron-expression-generator-quartz.html

2) Override the doReceive method in your scheduler class

This method will be called periodically based on your cron expression. You can write your business logic here which you want to execute periodically. i.e. you can write email sending and newsletter sending code here.

3) Register The scheduler

4) Deactivate the scheduler