2

I am creating multiple SlingJobs on the fly using org.apache.sling.commons.scheduler.Scheduler OSGi service in AEM.

i.e. scheduler.schedule(Runnable, ScheduleOptions);

I have requirement that these Sling Jobs be run only once, so I am using ScheduleOptions.AT(Date date,int times,long period) ScheduleOptions Docs

And passing times=1 as a parameter.

(Also what is period parameter ?)

The Job successfully runs only once.

My question is am I supposed to keep a track of this Job by name and UnSchedule it using Scheduler.unschedule(String jobName) after it has finished running ?

Will completed SlingJobs that are not UnScheduled, consume memory in the AEM server ?

Will these completed BUT unscheduled jobs cause my AEM server to slow down and later on require some purge activity as maintenance?

Oliver
  • 6,152
  • 2
  • 42
  • 75

1 Answers1

0

According to https://sling.apache.org/documentation/bundles/apache-sling-eventing-and-job-handling.html#scheduled-jobs

Internally the scheduled Jobs use the Commons Scheduler Service. But in addition they are persisted (by default below /var/eventing/scheduled-jobs) and survive therefore even server restarts. When the scheduled time is reached, the job is automatically added as regular Sling Job through the JobManager.

I had a problem with a scheduled jobs before(they were triggered on the daily basis). When the server was restarted scheduled jobs wasn't un-persisted and a new job doing the same action was scheduled(job was scheduled on @Activate method). As a result, I got several jobs doing the same action at the scheduled time, so I had to unschedule them in @Deactivate method.

You may make an experiment and make sure that there is no duplicated jobs under /var/eventing/scheduled-jobs

dzenisiy
  • 855
  • 10
  • 32