Expand my Community achievements bar.

Who Me Too'd this topic


Level 2

I'm trying to create a Sling job and not having much luck. I've followed the docs on the Apache and Adobe sites but if keeps throwing a null pointer exception. I figure I've missed an important step that wasn't in the docs I read. Also, everything I've read thats AEM related is based on a watcher seeing a change to the JCR or a scheduled task that runs at a set time. We want to trigger it without a JCR update.


My goal is to have a user perform an action that ends with a job being created and immediately ran. This would mean a servlet or API is hit and it adds the job and triggers it to run immediately. I've written code to do this but it throws the NPE on the jobManager.addJob() method call.


This is the Apache example code that I've based my code on.

Create the job

import org.apache.sling.jobs.JobManager;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Reference;
import java.util.Map;
import java.util.HashMap;

public class MyComponent {

    private JobManager jobManager;
    public void startJob() {
        final Map<String, Object> props = new HashMap<String, Object>();
        props.put("item1", "/something");
        props.put("count", 5);
        jobManager.addJob("my/special/jobtopic", props);


Job consumer

import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Service;
import org.apache.sling.event.jobs.Job;
import org.apache.sling.event.jobs.consumer.JobConsumer;

@Property(name=JobConsumer.PROPERTY_TOPICS, value="my/special/jobtopic",)
public class MyJobConsumer implements JobConsumer {

    public JobResult process(final Job job) {
        // process the job and return the result
        return JobResult.OK;

What I've been basing my work on.
Apache docs https://sling.apache.org/documentation/bundles/apache-sling-eventing-and-job-handling.html
Adobe https://experienceleague.adobe.com/docs/experience-manager-cloud-service/operations/asynchronous-job...
I've also exhausted my search skills on this topic.


Topics help categorize Community content and increase your ability to discover relevant content.

Who Me Too'd this topic