AEM6.2 sling models | Resource resolver is already closed

Avatar

Avatar

pradeepdubey82

Avatar

pradeepdubey82

pradeepdubey82

18-03-2018

Hi All,

I am  getting error in  sing model class saying resource resolver is already closed

Below is my code for reference.

@Model(adaptables = Resource.class)

public class SchedulerComponent {

private static Logger LOG = LoggerFactory.getLogger(SchedulerComponent.class);

@Inject

    private Date timer;

@Inject

private ResourceResolver resourceResolver;

@PostConstruct

public final void init() {

try {

     Session session = resourceResolver.adaptTo(Session.class);

} catch(Exception ex) {

}

}

}

Below is error stack trace.

java.lang.IllegalStateException: Resource resolver is already closed.

at org.apache.sling.resourceresolver.impl.ResourceResolverImpl.checkClosed(ResourceResolverImpl.java:202)

at org.apache.sling.resourceresolver.impl.ResourceResolverImpl.adaptTo(ResourceResolverImpl.java:826)

at com.test.core.models.SchedulerComponent$MyTimeTask.run(SchedulerComponent.java:69)

at java.util.TimerThread.mainLoop(Unknown Source)

at java.util.TimerThread.run(Unknown Source)

Please advise to fix the problem.

Thanks,

Pradeep

View Entire Topic

Avatar

Avatar

pradeepdubey82

Avatar

pradeepdubey82

pradeepdubey82

20-03-2018

@Inject

    private Date timer;

timer is the property in dialog of type Date.  This is needed to pass to schedule the task.

My requirement is to run  some piece  of code on  selected time. I am not using typical scheduler why because felix console access is not provided us, it is maintained and managed by Adobe, we can't ask them to run  scheduler as and when  needed. We have only author access. So in authoring dialog as soon as author is selecting particular date and time, my timer task code should execute. To accomplish this i am using java.util.TimerTask

Below code still throwing nullpointer for resourceresolver.

@SlingObject

private ResourceResolver resourceResolver;