コミュニティアチーブメントバーを展開する。

Submissions are now open for the 2026 Adobe Experience Maker Awards.
解決済み

Scheduler Job throwing exceptions

Avatar

Level 5

I tried writing a scheduler job using the Job class but somehow it won't execute. It keeps throwing null as an exception. This is what I'm getting in logs :

arindam6600_0-1702405819134.png

This is the code that I've written :

package com.mysite.core.schedulers;

import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;

import org.apache.sling.commons.scheduler.Job;
import org.apache.sling.commons.scheduler.JobContext;
import org.apache.sling.commons.scheduler.ScheduleOptions;
import org.apache.sling.commons.scheduler.Scheduler;
import org.osgi.service.component.annotations.Activate;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Deactivate;
import org.osgi.service.component.annotations.Reference;
import org.osgi.service.metatype.annotations.Designate;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

@Component(immediate = true, service = Job.class)
@Designate(ocd = SchedulerConfigThree.class)

public class PracticeSchedulerDayThree implements Job {
	private static final Logger LOG = LoggerFactory.getLogger(PracticeSchedulerDayThree.class);
	
	private int schedulerId;
	
	@Reference
	private Scheduler scheduler;
	
	@Activate
	protected void activate(SchedulerConfigThree configThree) {
		schedulerId = configThree.schedulerDayThreeName().hashCode();
		
		ScheduleOptions in = scheduler.EXPR("0 56 23 1/1 * ? *");
		Map<String, Serializable> inMap = new HashMap<>();
		inMap.put("country", "India");
		inMap.put("URL", "www.india.com");
		scheduler.schedule(this, in);
		
		ScheduleOptions de = scheduler.EXPR("0 59 23 1/1 * ? *");
		Map<String, Serializable> deMap = new HashMap<>();
		deMap.put("country", "Denmark");
		deMap.put("URL", "www.de.com");
		scheduler.schedule(this, de);
	}
	
	@Deactivate
	protected void deactivate() {
		scheduler.unschedule(String.valueOf(schedulerId));
	}

	@Override
	public void execute(JobContext jobContext) {
		LOG.info("\n ===> COUNTRY : URL {} : {}", jobContext.getConfiguration().get("country"), jobContext.getConfiguration().get("URL"));
	}

}

Can someone please let me know what am I doing wrong over here?

トピック

トピックはコミュニティのコンテンツの分類に役立ち、関連コンテンツを発見する可能性を広げます。

1 受け入れられたソリューション

Avatar

正解者
Community Advisor

It seems you forget to put the map config inside scheduleOptions object.

so basically you should be doing this one in.config(inMap) and de.config(deMap) before calling scheduler.schedule() in your class.

元の投稿で解決策を見る

2 返信

Avatar

正解者
Community Advisor

It seems you forget to put the map config inside scheduleOptions object.

so basically you should be doing this one in.config(inMap) and de.config(deMap) before calling scheduler.schedule() in your class.

Avatar

Level 5

Thank you @DPrakashRaj . Yes, I missed out that step. Thanks once again