Abstract
Howdy fellow devs . Welcome to day 16 of this AEM Developer Series. Today, we are going to delve into the nitty gritty details of Schedulers in AEM.
What are schedulers, you ask ? In simple terms, a scheduler is a service to schedule jobs. Thus, if we want some work to happen at a particular time or at a regular interval, then Schedulers are the way to go.
In AEM, we can create scheduler in two ways -
1. Whiteboard Pattern - In this, we create a Runnable thread to perform our task. This is similar to the Java Thread concept.
2. Scheduler API - In this, we use Apache Commons’ Scheduler API to perform our task. It uses open-source Quartz library.
Both of these methods can be seen here. However, from AEM 6.2 onwards Felix SCR annotations are deprecated and are replaced with OSGi annotations. Therefore, in this post, we will be discussing the clean way of creating schedulers that OSGi annotations provide.
Scheduler in AEM
To create a scheduler in AEM, we will follow the below steps -
1. Create an OSGi configuration to read the scheduler specific values from the user i.e. cron expression, the name of the scheduler, custom parameter etc.
2. Create a sling scheduler which displays the custom parameter at an interval specified by the cron expression.
Code Example
Let’s suppose your organization wants a report comprising workflow status and this report needs to be sent to a particular group of users via email every four hours. How will you achieve this? If you thought, I’d use a scheduler, then KUDOS to you. If you were not able to figure it out, then my sympathies are with you (Just Kidding ).
Read Full Blog
Q&A
Please use this thread to ask the related questions.
Kautuk Sahni