ATG supplies a scheduler of sorts that can be used to run tasks that are supposed to run on a recurring basis.
First, cd to your ATG installation directory, and set your CLASSPATH so that the compiler can find the needed ATG components against which to compile our test code.
cd /root/ATG/ATG10.0.3 #or wherever yours is located
export CLASSPATH=.:$(pwd)/Initial/lib/classes.jar
Using the example code from Oracle, we can compile the java class below. Create the HelloWorld.java file in $ATG_INSTALL_DIR/home/locallib
import atg.nucleus.*;
import atg.service.scheduler.*;
public class HelloJob extends GenericService implements Schedulable {
public HelloJob () {}
Scheduler scheduler;
public Scheduler getScheduler () {
return scheduler;
}
public void setScheduler (Scheduler scheduler) {
this.scheduler = scheduler;
}
Schedule schedule;
public Schedule getSchedule () {
return schedule;
}
public void setSchedule (Schedule schedule) {
this.schedule = schedule;
}
public void performScheduledTask (Scheduler scheduler,
ScheduledJob job) {
System.out.println ("Hello");
}
int jobId;
public void doStartService () throws ServiceException {
ScheduledJob job = new ScheduledJob ("hello",
"Prints Hello",
getAbsoluteName (),
getSchedule (),
this,
ScheduledJob.SCHEDULER_THREAD);
jobId = getScheduler ().addScheduledJob (job);
}
public void doStopService () throws ServiceException {
getScheduler ().removeScheduledJob (jobId);
}
}
Create a properties file for our component with the contents below. This should be created in $ATG_INSTALL_DIR/home/localconfig/test and be called HelloJob.properties
$class=HelloJob
$scope=global
scheduler=/atg/dynamo/service/Scheduler
schedule=every 1 minutes
If it doesn’t exist, create a file name Initial.properties in your $ATG_INSTALL_DIR/home/localconfig directory.
The Oracle example code is incorrect. The contents of the file should look similar to what is below
initialServices+=/test/HelloJob
Copy the HelloJob.class from $ATG_INSTALL_DIR/home/locallib to $JBOSS_DIR/server/yourappname/deploy/yourearfilename.ear/atglib/_atghome_slocallib
Restart the JBOSS server. We should see the job being executed every minute, which you can verify in the dynamo admin web interface located at http://hostname:port/dyn/admin/nucleus/atg/dynamo/service/Scheduler/
1 comment for “ATG scheduler job example”