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

19-03-2018

Not solved the issue even  after placed timertask logic in separate class

Nw below is my timertask class code

@Component

public class SchedulerTask extends TimerTask {

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

@Reference

private ResourceResolver resourceResolver;

Timer timer = new Timer();

private DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

public void run() {

    try {

}

}

}

Below error i am getting

org.apache.sling.api.scripting.ScriptEvaluationException: org.apache.sling.scripting.sightly.SightlyException: Identifier com.test.core.models.SchedulerComponent cannot be correctly instantiated by the Use API

I am  injecting timertask like below in main model class

@Inject

private SchedulerTask schedulerTask;