I was wondering what's the difference between Activate vs. Run in AEM scheduler? I am following this post: AEM 6.4 : Creating a Scheduler Using OSGi R6 Annotations | by Ankur Ahlawat | Adobe Tech Blog
In this article, I don't see any scheduler related code inside the run() method. What kind of code do I normally put inside the run() method and activate() method? Thanks!
Solved! Go to Solution.
Views
Replies
Total Likes
1. `run()` method: This method is the main entry point for the scheduled task's logic. It contains the code that executes when the scheduler is triggered according to its defined schedule. The `run()` method is responsible for performing the desired operations or executing the specific task for which the scheduler is designed.
For example, let's say you have a scheduler in AEM that is responsible for sending daily email notifications to subscribed users. The `run()` method of this scheduler would contain the logic to fetch the list of subscribed users, compose the email content, and send the email to each user.
Here's a simplified example of a scheduler with the `run()` method:
public class DailyEmailScheduler implements Runnable {
@Override
public void run() {
// Fetch the list of subscribed users
List<User> subscribedUsers = getUserService().getSubscribedUsers();
// Compose email content
String emailContent = composeEmailContent(subscribedUsers);
// Send email to each user
for (User user : subscribedUsers) {
EmailService.sendEmail(user.getEmail(), "Daily Update", emailContent);
}
}
// Other methods and dependencies...
}
In this example, the `run()` method is triggered according to the cron expression specified in the `scheduler.expression` property.
2. `activate()` method: This method is called when the scheduler is activated or enabled in the AEM instance. It is typically used to perform initialization tasks or set up any required resources before the scheduler starts running.
or perform initialization tasks when the scheduler is enabled.
Hi @aemUser2345 ,
@Activate annotation is used to notify your component that it is now loaded, resolved and ready to provide service.
@Modified annotation is notified when ever you make changes to the OSGI configuration properties and save them in /system/console/configMgr
@Deactivate is used when the component is deactivated
Run() method will be defining our task where our actual logic is executed at our scheduled time like sending emails or activating pages or generating sitemaps etc.,
Hope this helps,
Krishna
Hello @aemUser2345 -
1. run() Method :
2. activate() Method :
1. `run()` method: This method is the main entry point for the scheduled task's logic. It contains the code that executes when the scheduler is triggered according to its defined schedule. The `run()` method is responsible for performing the desired operations or executing the specific task for which the scheduler is designed.
For example, let's say you have a scheduler in AEM that is responsible for sending daily email notifications to subscribed users. The `run()` method of this scheduler would contain the logic to fetch the list of subscribed users, compose the email content, and send the email to each user.
Here's a simplified example of a scheduler with the `run()` method:
public class DailyEmailScheduler implements Runnable {
@Override
public void run() {
// Fetch the list of subscribed users
List<User> subscribedUsers = getUserService().getSubscribedUsers();
// Compose email content
String emailContent = composeEmailContent(subscribedUsers);
// Send email to each user
for (User user : subscribedUsers) {
EmailService.sendEmail(user.getEmail(), "Daily Update", emailContent);
}
}
// Other methods and dependencies...
}
In this example, the `run()` method is triggered according to the cron expression specified in the `scheduler.expression` property.
2. `activate()` method: This method is called when the scheduler is activated or enabled in the AEM instance. It is typically used to perform initialization tasks or set up any required resources before the scheduler starts running.
or perform initialization tasks when the scheduler is enabled.
Views
Likes
Replies
Views
Likes
Replies
Views
Likes
Replies
Views
Likes
Replies