Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

Adobe Summit 2023 [19th to 23rd March, Las Vegas and Virtual] | Complete AEM Session & Lab list

How to create scheduler to run the sling servlet?


Level 2

Hi All,


We have a requirement to execute the sling servlet on the monthly basis. Actually I have added the content path of the sites in xml and updated this in content/dam, here I have used query builder for this and I wanted to execute this particular servlet on the monthly basis to generate the xml.


Please let me know if anyone has worked on the similar issue.



5 Replies


Community Advisor

I think, you should move the servlet logic into the osgi service/component e.g. DoSomethingService and call that service in servlet e.g. ThisMyServlet and in your scheduler MyScheduler.


If you do not need servlet you can simply remove the servlet e.g. ThisMyServlet


Level 2

Hi @arunpatidar ,

I have done the same way. I have created a service and called this service in servlet. Do I need to call this service in scheduler as well?




Employee Advisor

Hi @aaqibk92586681 ,


Whatever @arunpatidar suggested should help.

However, the use case you mentioned only needs a service (DoSomethingService) & a scheduler(MyScheduler that invokes DoSomething.doing()) which uses the service at given frequency according to CRON expression.

But, incase you also need an manual option to do the task, you can have a servlet at some path (/bin/execute/dosomething) and call it if required.

This approach will enable :
1. Scheduled job to do the task using scheduler at given frequency.
2. Option to also do the same job on demand by hitting the servlet endpoint.

And both would be using the same service custom code (here, DoSomething.doing())




Level 2

Hi @milind_bachani ,

For now we are hitting below servlet manually to add the xml file in dam.


I created a service class to generated the searched path via query builder and I have called this particular service in servlet and I wanted to this servlet run on monthly basis that's why I wanted to add scheduler. Is there any way we can configure servlet path in scheduler config to execute this servlet and after running the scheduler the above process will generate automatically.