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

Avatar

Avatar

elizabethp60981

Avatar

elizabethp60981

elizabethp60981

01-10-2019

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

Accepted Solutions (1)

Accepted Solutions (1)

Avatar

Avatar

jbrar

Employee

Avatar

jbrar

Employee

jbrar
Employee

02-10-2019

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

Answers (1)

Answers (1)

Avatar

Avatar

Himanshu_Singhal

MVP

Avatar

Himanshu_Singhal

MVP

Himanshu_Singhal
MVP

02-10-2019

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