Expand my Community achievements bar.

SOLVED

AEM6.4 - org.apache.sling.commons.scheduler Cron error

Avatar

Level 3

Hi,

I am using the library org.apache.sling.commons.scheduler to create a scheduler on AEM

I am using the example below, that I found in sling documentation (Apache Sling :: Scheduler Service (commons scheduler) ) and it is working as it is, but I need to change the scheduled time to trigger every 15 minutes between 8:00a.m and 10:00am

My method:

String schedulingExpression = "0 * * * * ?";

String jobName1 = "case1";

Map<String, Serializable> config1 = new HashMap<String, Serializable>();

boolean canRunConcurrently = true;

final Runnable job1 = new Runnable() {

     public void run() {

              log.info("Executing job1");

     }

};

try {

    this.scheduler.addJob(jobName1, job1, config1, schedulingExpression, canRunConcurrently);

} catch (Exception e) {

           job1.run();

}

The problem is that everytime that I change the cron expression for anything else I have the error:

java.lang.IllegalArgumentException: Expressionis invalid : 0,15,30,45 8-10 * * *

The 0,15,30,45 8-10 * * *  is the expression that I am trying to use, online cron validators says that this is a valid expression.

Does someone have a clue of what is going on?

Thanks in advance!!!

1 Accepted Solution

Avatar

Correct answer by
Employee Advisor

It's the missing question mark at the end. Always test the cron using an online tool before using it in the code.

Screen Shot 2019-10-02 at 10.45.48 AM.png

Screen Shot 2019-10-02 at 10.46.19 AM.png

View solution in original post

2 Replies

Avatar

Community Advisor

Hi,

0,15,30,45 8-10 * * * ? - it's the valid expression but not 0,15,30,45 8-10 * * *

Just checked it out there Free Online Cron Expression Generator and Describer - FreeFormatter.com

Avatar

Correct answer by
Employee Advisor

It's the missing question mark at the end. Always test the cron using an online tool before using it in the code.

Screen Shot 2019-10-02 at 10.45.48 AM.png

Screen Shot 2019-10-02 at 10.46.19 AM.png