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
BedrockMission!

Learn more

View all

Sign in to view all badges

SOLVED

AEM Scheduler running even if scheduler is disabled and Bundle is stopped

sg08
Level 2
Level 2

Hi,

 

I had created a custom scheduler for sending emails based on inbox tasks in aem. It was working properly until a day ago when suddenly, even if the scheduler is disabled, and the bundle is stopped, it is still somehow running and I get emails for newly created tasks. But in the project logs it shows that the scheduler has been stopped and no evidence of the code being executed. So a different scheduler is somehow still running and it is not part of this bundle?

Please let me know how I should go about fixing this issue and finding/stopping that scheduler. 

 

Thanks.

Adobe Experience Manager AEM AEM 6.5 bundle Configuration osgi scheduler scheduling
1 Accepted Solution
Nupur_Jain
Correct answer by
Community Advisor
Community Advisor

Hi @sg08 

 

Scheduler or we can say thread can still run even if the bundle is down. We have to remove scheduler on deactivation of scheduler service. You can remove it in @Deactivate annotated method of your service. Find the sample snippet:

 

@Component(immediate = true)
public class TestScheduler implements Runnable {

    @Reference
    private Scheduler scheduler;

    private String schedulerId = "Scheduler";
    
    @Activate
    @Modified
    protected void activate() {
        addScheduler();
    }

    @Deactivate
    protected void deactivate() {
        removeScheduler();
    }

    private void removeScheduler() {
        scheduler.unschedule(String.valueOf(schedulerId));
    }

    private void addScheduler() {
        ScheduleOptions scheduleOptions = scheduler
                .EXPR("");
        scheduleOptions.name(String.valueOf(schedulerId));
        scheduler.schedule(this, scheduleOptions);
    }

    @Override
    public void run() {
    	//what needs to be done
    }

}

 

Hope it helps!

View solution in original post

11 Replies
Nupur_Jain
Correct answer by
Community Advisor
Community Advisor

Hi @sg08 

 

Scheduler or we can say thread can still run even if the bundle is down. We have to remove scheduler on deactivation of scheduler service. You can remove it in @Deactivate annotated method of your service. Find the sample snippet:

 

@Component(immediate = true)
public class TestScheduler implements Runnable {

    @Reference
    private Scheduler scheduler;

    private String schedulerId = "Scheduler";
    
    @Activate
    @Modified
    protected void activate() {
        addScheduler();
    }

    @Deactivate
    protected void deactivate() {
        removeScheduler();
    }

    private void removeScheduler() {
        scheduler.unschedule(String.valueOf(schedulerId));
    }

    private void addScheduler() {
        ScheduleOptions scheduleOptions = scheduler
                .EXPR("");
        scheduleOptions.name(String.valueOf(schedulerId));
        scheduler.schedule(this, scheduleOptions);
    }

    @Override
    public void run() {
    	//what needs to be done
    }

}

 

Hope it helps!

View solution in original post

sg08
Level 2
Level 2

Hi @Nupur_Jain , thank you for the response.

 

Yes, I am already using the code snippet you shared in my code.

 

@Deactivate
protected void deactivate(AkamDASHSchedulerConfiguration dashOSGIConfiguration) {
log.info("DeActivate method");

removeScheduler(dashOSGIConfiguration);
}
private void removeScheduler(AkamDASHSchedulerConfiguration dashOSGIConfiguration) {
log.info("RemoveScheduler method");

// unscheduling/removing the scheduler
scheduler.unschedule(conDASHSCHEDULERCONFIG);
}


It was working properly until a day ago. It should show the scheduler going to run method in the project log if that's the case but it doesn't. So it looks like there is a duplicate/cached scheduler which is somehow still running.. Any idea how I should solve this issue?

Nupur_Jain
Community Advisor
Community Advisor

@sg08 

 

There is system console to check for registered schedulers.

Check http://host:port/system/console/status-slingscheduler to check if you see your scheduler there.

Veena_Vikram
Community Advisor
Community Advisor

Can you check if there is any active jobs running ? If you check /var/eventing/jobs , may be you can find any active jobs running. 

sg08
Level 2
Level 2
Good point, I can check that. However the URL your provided doesn't seem to work (/var/eventing/jobs). Did it get moved?
Singaiah_Chintalapudi
Community Advisor
Community Advisor

You can check existing jobs under:/var/evening/jobs and also check the scheduler config under: /system/console/configMgr just to make sure the scheduler is disabled or removed.

Nupur_Jain
Community Advisor
Community Advisor

@sg08 

 

There is system console to check for registered schedulers.

Access http://host:port/system/console/status-slingscheduler to check if you see your scheduler there.

sg08
Level 2
Level 2
Hi @Nupur_Jain , yes, I was able to see my scheduler in the active jobs list in /system/console/status-slingscheduler. Anyway the issue seems to have resolved by itself for now so I am monitoring it. Thanks for the help
Nupur_Jain
Community Advisor
Community Advisor

@sg08 

 

Can you mark this answer as correct if it helped you.

 

 

Manish_Singh_1
Employee
Employee

Few steps:

 

1. Check if the scheduler is active from /system/console/status-slingscheduler. 

2. If not active then, Restart AEM

3. Check if you are using a workflow step which may be sending emails 

 

if not then open a support ticket for further investigation