AEM6.4 - org.apache.sling.commons.scheduler Cron error | Community
Skip to main content
elizabethp60981
New Participant
October 2, 2019
Solved

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

  • October 2, 2019
  • 2 replies
  • 3581 views

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

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

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

2 replies

user05162Accepted solution
Employee
October 2, 2019

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

Himanshu_Singhal
New Participant
October 2, 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