Share

Implementing CRON Jobs through Quartz

First of all we have to know the what is CRON Job.It is defined as follows

A CRON job is time based job scheduler.People who setup and maintain software environments use CRON to schedule jobs to run periodically at fixed times,dates or intervals.

Liferay has an in-built feature to support this feature with the help of powerful scheduling and triggering engine called Quartz

Now lets go technically how to use this feature in our portlet development.

Usecase: 
Suppose i am maintaining a one blog which posts the technical details of the Liferay.Now what i am doing is when user registering into the blog he/she has provision to select for monthly news letter

If he/she is willing to take monthly news letter then automatically on every month user will be able to get the news letter on email through Quartz.

Creating a Quartz in Liferay is two step process 

          1. Write a job itself
          2.  Configure and registering a job Quartz Scheduler that is running inside the server

Now lets implement 

1. Create one portlet
2. Create on package com.blognewsletter.job and create one class NotifyNewsLetter inside the package which implements the MessageListener


package com.blognewsletter.job;

import com.liferay.portal.kernel.messaging.Message;
import com.liferay.portal.kernel.messaging.MessageListener;
import com.liferay.portal.kernel.messaging.MessageListenerException;

public class NotifyNewsLetter implements MessageListener {

@Override
public void receive(Message arg0) throws MessageListenerException {
// TODO Auto-generated method stub
System.out.println("This is coming from CRON Job scheuled for every 7 Minutes");
}

}

    Note:step1 completed i.e defining CRON job.
3. Open liferay-portlet.xml and add the following entries immediately after icon tag

4. Deploy the portlet now observe the console .You can see the following messagae for every 7 sec
    "This is coming from CRON Job scheuled for every 7 minutes".
   

Download Source Code Here

2 comments:

  1. This Blog appears to receive a great deal of visitors or customer who is looking for natural stones such as granite kitchen worktops, Marble kitchen Worktops and Quartz kitchen Worktops. How do you get traffic to it? It offers a nice unique spin on things. I guess having something useful or substantial to give info on is the most important thing. https://www.astrumgranite.com/how-can-i-change-my-kitchen-worktops-in-easy-step/

    Thank You!!!

    ReplyDelete
  2. Your Blog is amazing. If you want to know that HOW TO SETUP A CRON JOB then,
    Click here for more information:
    HOW TO SETUP A CRON JOB

    ReplyDelete