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

Avatar

Avatar
Ignite 1
Level 1
Debal-Das
Level 1

Likes

0 likes

Total Posts

3 posts

Correct reply

0 solutions
Top badges earned
Ignite 1
Give Back
View profile

Avatar
Ignite 1
Level 1
Debal-Das
Level 1

Likes

0 likes

Total Posts

3 posts

Correct reply

0 solutions
Top badges earned
Ignite 1
Give Back
View profile
Debal-Das
Level 1

19-07-2021

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

Accepted Solutions (1)

Accepted Solutions (1)

Avatar

Avatar
Contributor
Level 4
Bimmi_Soi
Level 4

Likes

68 likes

Total Posts

76 posts

Correct reply

24 solutions
Top badges earned
Contributor
Applaud 5
Boost 50
Ignite 1
Affirm 10
View profile

Avatar
Contributor
Level 4
Bimmi_Soi
Level 4

Likes

68 likes

Total Posts

76 posts

Correct reply

24 solutions
Top badges earned
Contributor
Applaud 5
Boost 50
Ignite 1
Affirm 10
View profile
Bimmi_Soi
Level 4

19-07-2021

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 

 

Answers (1)

Answers (1)

Avatar

Avatar
Coach
MVP
Arun_Patidar
MVP

Likes

1,431 likes

Total Posts

3,305 posts

Correct reply

937 solutions
Top badges earned
Coach
Contributor 2
Ignite 10
Give Back 700
Boost 1000
View profile

Avatar
Coach
MVP
Arun_Patidar
MVP

Likes

1,431 likes

Total Posts

3,305 posts

Correct reply

937 solutions
Top badges earned
Coach
Contributor 2
Ignite 10
Give Back 700
Boost 1000
View profile
Arun_Patidar
MVP

20-07-2021

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.