If the Dynamo application want to perform a task at regular
intervals of time or a period of time it includes a scheduler service
(atg.service.scheduler.Scheduler) which executes the appropriate services at
specified times.
Dynamo also includes a SingletonSchedulableService,
atg.service.scheduler.SingletonSchedulableService,
which enables multiple Dynamo servers to run the same scheduled service, while
guaranteeing that only one instance of the service performs the scheduled task
at a time. This provides some protection from server failures, as the loss of
one Dynamo server does not prevent the scheduled service from running on
another Dynamo server.
Scheduling a Task in ATG:
In order to schedule a task, a component needs a pointer to
the Scheduler, which is usually set as a component property. The component
schedules a new task by calling
addScheduledJob
on the Scheduler. The Scheduler executes the job as scheduled.
When the Scheduler executes a job, it calls
performScheduledTask
on the object that
performs the task, which must implement atg.service.scheduler.Schedulable
.
Typically, the component that schedules the task is also the Schedulable
component that executes it,
but this is not strictly required.
When a component schedules a task, it must provide the
Scheduler with the following information:
·
A name for the scheduled job; used only for
display to the administrator.
·
The name of the component scheduling the job;
used only for display to the administrator.
·
The
Schedulable
object that handles the job; typically, the same as the component that
schedules the job.
·
A flag that indicates how to run the job:
o In
a separate thread.
o In
the same thread as other scheduled services.
o In
a dedicated, reusable thread.
If a job runs in the same thread as other
services, no other scheduled services can run until the job finishes. If the
job is long and expensive, it should run in a separate thread. If the job is
short, it should run in the same thread. The
Schedule
that indicates when the job should run. This is specified as an object that
implements atg.service.scheduler.Schedule
.
The scheduler
package
provides a set of useful Schedule
types, including schedules that represent an event at a specific time,
schedules that represent periodic events, and schedules that represent events
based on the calendar—for example, on the 1st and 15th of every month. Usually
the Schedule
is passed in as
a property. All of this information is encapsulated in a ScheduledJob
object, which is passed to
the Scheduler’s addScheduledJob()
method.When
a job is added to the Scheduler, the Scheduler returns an integer job ID, which
you can later use to reference that job. For example, to stop a scheduled job,
you can call removeScheduledJob
on the Scheduler, passing in the ID of the job to stop.Add your component to one of the inital arrays in an Initial component.
In initial.properties add your scheduler component created to initialServices property.
If you want to run the schedulers manually you can do it from dyn/admin.