Schedulers Job in Oracle ATG

Schedulers in Oracle ATG

In Oracle ATG we have Scheduler to run recurring tasks. These tasks are scheduled to run at a predefined time everyday or week as configured.

Steps in implementing Scheduler in Oracle ATG

Step 1: We have to Create a new class extending atg.service.scheduler.SchedulableService (SampleScheduler.java)
Step2 :  Implement: performScheduledTask(Scheduler pScheduler, ScheduledJob pJob)

Step 3: We have create Component for the above class. (SampleScheduler.properties)

Schedulers in Oracle ATG

Schedulers in Oracle ATG

Below is the template for implementing any scheduler in Oralce ATG, we have covered the best practices – like logging and Performance monitoring along with the above steps in defining a Scheduler Job in oracle ATG.

SampleScheduler.java

import atg.nucleus.ServiceException;
import atg.service.perfmonitor.PerformanceMonitor;
import atg.service.scheduler.ScheduledJob;
import atg.service.scheduler.Scheduler;
import atg.service.scheduler.SingletonSchedulableService;
/**
 * This class is responsible for _______. This scheduler runs every 24 hour to _______.
 */
public class SampleScheduler extends SingletonSchedulableService{
 
 // ANY COMPONENT CAN BE INJECTED WITH GETTER AND SETTER - AND CAN BE USED IN YOUR LOGIC
/** The Constant INVENTORY_FEED_IMPORT*/
 public static final String SAMPLE_JOB_NAME = "jobName";
 
 /** The Constant UPDATE_INVENTORY_STOCK_LEVEL*/
 public static final String SAMPLE_JOB_DESCRIPTION = "JOB DESCRIPTION";
 
 /** The Constant START_OPERATION*/
 public static final String START_OPERATION = "SampleScheduler - doScheduledTask()";
 
 /** The Constant END_OPERATION*/
 public static final String END_OPERATION = "SampleScheduler - doScheduledTask()";
 /**
 * Method responsible for starting the Sample feed scheduling
 * based on configured scheduler.
 * 
 * @throws ServiceException the service exception
 */
 @Override
 public void doStartService() throws ServiceException {
   if (isLoggingDebug()) {
      logDebug("Entering into SampleScheduler: doStartService() method");
   }
 
   final ScheduledJob job = new ScheduledJob(SAMPLE_JOB_NAME,
   SAMPLE_JOB_DESCRIPTION, getAbsoluteName(),
   getSchedule(), this, ScheduledJob.SCHEDULER_THREAD);
   if(isLoggingDebug()){
     logDebug("The created job object is"+job);
   }
 
   mJobId = getScheduler().addScheduledJob(job);
   if(isLoggingDebug()){
      logDebug("The created jobId is "+ mJobId);
   }
 }
 
 /**
 * Method responsible for stopping the sample feed scheduling 
 * based on configured scheduler. 
 * @throws ServiceException - Exception
 */
 @Override
 public void doStopService() throws ServiceException {
   if (isLoggingInfo()) {
     logInfo("Entering into SampleScheduler: doStopService() method");
   }
   getScheduler().removeScheduledJob(getJobId());
   if (isLoggingInfo()) {
     logInfo("Exiting from SampleScheduler: doStopService() method");
   }
 }
 
 /**
 * This method is extended from SingletonSchedulableService class to execute the scheduler task.
 * @param pScheduler - Scheduler
 * @param pScheduledJob - ScheduledJob
 */
 public void performScheduledTask(Scheduler pScheduler, ScheduledJob pScheduledJob) {
   if (isLoggingDebug()) {
     logDebug("Entering performScheduledTask()..SampleScheduler");
   }
   if(PerformanceMonitor.isEnabled()) {
     PerformanceMonitor.startOperation(START_OPERATION);
   }
   try {
     // LOGIC FOR SAMPLE JOB
   }
   finally {
     if(PerformanceMonitor.isEnabled()) {
       PerformanceMonitor.endOperation(END_OPERATION);
     } 
   }
   if (isLoggingDebug()) {
     logDebug("exitting performScheduledTask() in SampleScheduler");
   }
 } 
 
 /**
 * This method is extended from SingletonSchedulableService class to execute the scheduler task.
 * 
 * @param pScheduler - Scheduler
 * @param pScheduledJob - ScheduledJob
 */
 @Override
 public void doScheduledTask(Scheduler pScheduler, ScheduledJob pScheduledJob) {
   if (isLoggingInfo()) {
     logInfo("BEGIN : SampleScheduler(doScheduledTask)");
   }
 
   if (isLoggingInfo()) {
     logInfo("END : SampleScheduler(doScheduledTask)");
   }
 }
}

SampleScheduler.properties

 # This files holds the feed scheduler component for Sample feed
 $class=com.data.scheduler.SampleScheduler

#OOTB scheduler for doing schedule job
 scheduler=/atg/dynamo/service/Scheduler

#OOTB This property holds the schedule.
 schedule=every 24 hours

#OOTB client lock manager
 clientLockManager=/atg/dynamo/service/ClientLockManager

# OOTB client lockName
 lockName=ReportingLockManager

# OOTB client lockTimeOut
 lockTimeOut=20000

#This property hold name of the catalog feed job
 jobName=SampleFeedScheduler

#This property holds Catalog feed job description
 jobDescription=Sample Feed Scheduler

#This property holds job threadMethod
 threadMethod=2

You may also like this

seperator

About TechnoStixs.com

Oracle ATG Web Commerce States

TechnoStixs.com is a dedicated weblog for Java/J2EE and web developers. We take pride in our work. Every publication is carefully analyzed, written and tested to ease the understanding of the topic or subject.

We cover Java Core Technologies, eCommerce, J2EE Frameworks, Web Service, Build Tools, Unit Test Frameworks and Others.

2,766 total views, 1 views today

Add comment