8.1 Create New Scheduler Class

Follow the steps given below while creating new scheduler:

  1. Implement the class with org.quartz.Job, java.io.Serializable.

    Example

    public class ReportSchedulerImpl implements Serializable, Job {}
  2. Define the required business logic in the overridden method execute(JobExecutionContext) required for scheduling.

    Example

    @Overridepublic void execute
    (JobExecutionContext paramJobExecutionContext) throws JobExecutionException
    {// business logic required for scheduling}
  3. Get the SessionContext and AccessPoint objects from the method parameter before calling the business logic (if any). Set both the objects in the thread attributes.

    Example

    SessionContext sessionContext = (SessionContext) 
    paramJobExecutionContext.getJobDetail().getJobDataMap().get("sessionContext");
    AccessPointDTO accessPoint = (AccessPointDTO) 
    paramJobExecutionContext.getJobDetail().getJobDataMap().get("accessPoint");
    com.ofss.digx.infra.thread.ThreadAttribute.set(com.ofss.digx.infra.thread.ThreadAttribute.ACCESS_POINT,
    accessPoint);ThreadAttribute.set(ThreadAttribute.SESSION_CONTEXT, sessionContext);
  4. Call the respective service class (if any) for business logic.

    Example

    try {
            ReportRequest service = new 
            ReportRequest();service.executeScheduled(sessionContext);
                } 
            catch (Exception e) 
            {
                logger.log(Level.SEVERE, "Error occurred while executing ReportSchedulerImpl
                class at : " + new java.util.Date(), e);  
            } 
            catch (java.lang.Exception e) 
            {
                logger.log(Level.SEVERE, "Error occurred while executing ReportSchedulerImpl
                class at : " + new java.util.Date(), e);
            }