Expand my Community achievements bar.

Dive into Adobe Summit 2024! Explore curated list of AEM sessions & labs, register, connect with experts, ask questions, engage, and share insights. Don't miss the excitement.
SOLVED

How JCR session and ResourceResolver are getting closed in groovy script?

Avatar

Level 1

Hello All,

We know that binding variables like 
session - javax.jcr.Session

resourceResolver - org.apache.sling.api.resource.ResourceResolver are available for use in groovy scripts.

We can use this JCR session to execute SQL queries, update node properties. 

But, we are not closing JCR Session and ResourceResolver explicitly like session.logout() and resourceResolver.close() in groovy script.

 

How resourceResolver and session are getting closed automatically in groovy script?

 

Thanks,

Debal

1 Accepted Solution

Avatar

Correct answer by
Employee Advisor

Hi @Debal-Das ,

If you are not opening any resource or session, you don't have to close it

Session and ResourceResolver objects that are obtained via the SlingRequest or WorkflowSession do not close by your application.  For example:

slingRequest.getResourceResolver().adaptTo(Session.class);
//Or
workflowSession.getSession();

That resolver or session closes automatically after the request has been processed.

 

https://helpx.adobe.com/experience-manager/kb/Random-Resource-resolver-is-already-closed-in-the-logs...

 

Hope this helps.

 

Thanks 

 

View solution in original post

2 Replies

Avatar

Correct answer by
Employee Advisor

Hi @Debal-Das ,

If you are not opening any resource or session, you don't have to close it

Session and ResourceResolver objects that are obtained via the SlingRequest or WorkflowSession do not close by your application.  For example:

slingRequest.getResourceResolver().adaptTo(Session.class);
//Or
workflowSession.getSession();

That resolver or session closes automatically after the request has been processed.

 

https://helpx.adobe.com/experience-manager/kb/Random-Resource-resolver-is-already-closed-in-the-logs...

 

Hope this helps.

 

Thanks 

 

Avatar

Community Advisor

Hi,

If you are not opening any resource or session, you don't have to close it.

Similar when you get a session from a request or getting PrintWriter from a response, you use it and leave it because you did not open it explicitly.

 

and you should not close any resource/session if you did not open it.

 

 



Arun Patidar