Expand my Community achievements bar.

Guidelines for the Responsible Use of Generative AI in the Experience Cloud Community.
SOLVED

Schedulers in AEM

Avatar

Level 4

Hey Guys,

 

I want to know the difference between White board pattern and Scheduler API for scheduled execution of the code. Which method is preferred ? Please help me.  

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

Hello @Prashanth_02a 

 

a. Whiteboard Pattern: create a simple Runnable thread to perform a specific task at regular intervals.

Pros:

- Simplicity: The Whiteboard Pattern is straightforward and easy to implement. You create a simple Runnable thread that performs your task.
- Light-weight: It typically involves fewer dependencies and is suitable for simple scheduling tasks.

Cons:
- Limited features: The Whiteboard Pattern might be more suitable for basic scheduling tasks, but it may lack some advanced scheduling features provided by Quartz.

 

b. Scheduler API (using Quartz): Describing how to use the Apache Commons Scheduler API with Quartz to implement more complex and feature-rich scheduling tasks, utilizing the powerful features provided by Quartz library for job scheduling. https://www.quartz-scheduler.org/ 

 

Quartz is a powerful and mature library with a wide range of scheduling features, such as cron expressions, repeat intervals.

 

Implementation details: https://sling.apache.org/documentation/bundles/scheduler-service-commons-scheduler.html#examples-of-...

 

In summary, if you have simple and basic scheduling needs, the Whiteboard Pattern can be sufficient. However, if you require advanced scheduling features, job management, and better control over your scheduled tasks, then the Scheduler API with Quartz might be a more suitable choice.

 

Incase you use Whiteboard pattern, please make sure you replace SCR with OSGi R6 annotations 


Aanchal Sikka

View solution in original post

3 Replies

Avatar

Employee

Hi @Prashanth_02a ,If you are already working within an OSGi environment, the Whiteboard Pattern can be a powerful and flexible choice and if you are not using OSGi or do not have complex scheduling requirements, the Scheduler API provided by your framework or library might be the preferred and simpler option.

Avatar

Employee

@Prashanth_02a You can choose any option based on your requirement

Whiteboard pattern — Creation of scheduler with the help of Runnable interface implementation and overriding protected void activate(final Config config) method.

Examples of jobs that are scheduled by leveraging the whiteboard pattern

1)Scheduling with a cron expression
2)Scheduling at periodic times
3)Preventing concurrent execution
4)Scheduling the job just once in a cluster

 

Scheduler API — Scheduler created with the help of Scheduler OSGI Service using @Reference annotation.

 

Examples of scheduled jobs registered through the scheduler API
1) Defining the job
2) Scheduling with a cron expression
3) Scheduling at periodic times
4) Scheduling at a given time

 

Please avoid using white board pattern as scr annotations are deprecated.

Avatar

Correct answer by
Community Advisor

Hello @Prashanth_02a 

 

a. Whiteboard Pattern: create a simple Runnable thread to perform a specific task at regular intervals.

Pros:

- Simplicity: The Whiteboard Pattern is straightforward and easy to implement. You create a simple Runnable thread that performs your task.
- Light-weight: It typically involves fewer dependencies and is suitable for simple scheduling tasks.

Cons:
- Limited features: The Whiteboard Pattern might be more suitable for basic scheduling tasks, but it may lack some advanced scheduling features provided by Quartz.

 

b. Scheduler API (using Quartz): Describing how to use the Apache Commons Scheduler API with Quartz to implement more complex and feature-rich scheduling tasks, utilizing the powerful features provided by Quartz library for job scheduling. https://www.quartz-scheduler.org/ 

 

Quartz is a powerful and mature library with a wide range of scheduling features, such as cron expressions, repeat intervals.

 

Implementation details: https://sling.apache.org/documentation/bundles/scheduler-service-commons-scheduler.html#examples-of-...

 

In summary, if you have simple and basic scheduling needs, the Whiteboard Pattern can be sufficient. However, if you require advanced scheduling features, job management, and better control over your scheduled tasks, then the Scheduler API with Quartz might be a more suitable choice.

 

Incase you use Whiteboard pattern, please make sure you replace SCR with OSGi R6 annotations 


Aanchal Sikka