AEM cronjob based on certain time interval
I am trying to create a cronjob in cq using a time interval
I see on the link https://sling.apache.org/documentation/bundles/scheduler-service-commons-scheduler.html i could job1 and it will work .But i questions on the code.
In the below code
1.Why the job1.run() is invovked in catch block .cannot we add it try block
2.can i replace the catch block instead of job1.run() using thread using start and can i add in try block or it must be catch block
Thread newThread= new Thread(job1);
newThread.start();
protected void activate(ComponentContext componentContext) throws Exception {
//case 1: with addJob() method: executes the job every minute
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();
}