Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
BedrockMission!

Learn more

View all

Sign in to view all badges

SOLVED

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

Debal-Das
Level 1
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
Bimmi_Soi
Correct answer by
Community Advisor
Community 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
Bimmi_Soi
Correct answer by
Community Advisor
Community 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

Arun_Patidar
Community Advisor
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.