Sheduled job does not work anymore (Scheduling service [java.lang.Runnable] failed) | Community
Skip to main content
Magicr
Level 6
October 18, 2022
Solved

Sheduled job does not work anymore (Scheduling service [java.lang.Runnable] failed)

  • October 18, 2022
  • 3 replies
  • 2589 views

The logfile error.log shows me following error:

18.10.2022 14:20:44.980 *INFO* [CM Event Dispatcher (Fire ConfigurationEvent: pid=xx.xxx.MyCronJob)] xx.xxx.my-bundle Service [xx.xxx.MyCronJob,9912, [java.lang.Runnable]] ServiceEvent UNREGISTERING 18.10.2022 14:20:44.985 *ERROR* [CM Event Dispatcher (Fire ConfigurationEvent: pid=xx.xxx.MyCronJob)] org.apache.sling.commons.scheduler.impl.WhiteboardHandler Scheduling service [java.lang.Runnable] failed. 18.10.2022 14:20:44.985 *INFO* [CM Event Dispatcher (Fire ConfigurationEvent: pid=xx.xxx.MyCronJob)] xx.xxx.my-bundle Service [xx.xxx.MyCronJob,9913, [java.lang.Runnable]] ServiceEvent REGISTERED

 

The configuration class looks so:

public @interface MyCronJobConfig { @AttributeDefinition(name = "Cron Pattern", description = "...") String scheduler_expression() default "0 30 2 * * *"; @AttributeDefinition(name = "Concurrent Jobs", description = "...", type = AttributeType.BOOLEAN) boolean scheduler_concurrent() default true; @AttributeDefinition(name = "Enabled", description = "...", type = AttributeType.BOOLEAN) boolean enabled() default true; }

 

And the business logic:

@8220494(service = Runnable.class, immediate = true, configurationPolicy = ConfigurationPolicy.REQUIRE) @Designate(ocd = MyCronJobConfig.class) @Slf4j public class MyCronJob implements Runnable { private BundleContext bundleContext; protected void activate(ComponentContext componentContext) throws Exception { this.bundleContext = componentContext.getBundleContext(); log.info("cron job activated."); } public void run() { log.info("cron job started."); log.info("cron job finished."); } }

The problem is, the run() method won't be executed. I can see it while no log output does appear in log file. Where is my mistake?

 

Thanks for your help.

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.

3 replies

Level 3
October 18, 2022

Hi @magicr , Please follow the tutorial in the motioned link https://aem.redquark.org/2018/10/day-13-schedulers-in-aem.html

I think lot needs to be added in the business logic to make the scheduler.

 

arunpatidar
Community Advisor
Community Advisor
October 18, 2022

you need to add osgi config because of 

configurationPolicy = ConfigurationPolicy.REQUIRE
Arun Patidar
Magicr
MagicrAuthor
Level 6
October 19, 2022

Where do I have to  place this line? If you look at my posted code snippets I have alerady added it.

arunpatidar
Community Advisor
arunpatidarCommunity AdvisorAccepted solution
Community Advisor
October 19, 2022
manjunathdj
October 18, 2022

@magicr -

Refer

https://blog.developer.adobe.com/aem-6-4-creating-a-scheduler-using-osgi-r6-annotations-4ad0b8c6fce7

Also @arunpatidar  is correct as per your code make sure you not missing configurations. 

configurationPolicy = ConfigurationPolicy.REQUIRE

 

Thanks

Magicr
MagicrAuthor
Level 6
October 19, 2022

Have you also read my code snippets? The annotations do exists, the line for confugurationPolicy exists either. Also, the activation method will be executed and the configuration does appear in webconsole from AEM.

December 8, 2022

Hi Are you able to solve this. We are facing the same issue. Can you post the solution here.