ResourceResolver Closure in Servlet | Community
Skip to main content
May 2, 2023
Solved

ResourceResolver Closure in Servlet

  • May 2, 2023
  • 2 replies
  • 727 views

Hi Team,

 

I have created ResourceResolver from request object of the Servlet. Do we need to close it manually in the Servlet?

 

1) PageManager pageManager = request.getResourceResolver().adaptTo(PageManager.class);

2) Session session=request.getResourceResolver().adaptTo(Session.class);

String  newurl =  "/jcr:content/root/responsivegrid/responsivegrid/login";
3) Resource resource = request.getResourceResolver().getResource(newurl);

 

 

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by Pulkit_Jain_

@shyamasundar-ks 

I think getResourceResolver() does not create a new ResourceResolver; as a best practice, we recommend using the try-with-resources statement that ensures that each resource is closed at the end of the statement, with the most commonly used way to make a new ResourceResolver i.e ResourceResolverFactory.

More info here- https://cqdump.joerghoh.de/2018/11/14/try-with-resource-or-i-will-never-forget-to-close-a-resource-resolver/ 

2 replies

Vijay_Katoch
Community Advisor
Community Advisor
May 2, 2023

I think, no need to close it explicitly.

 

Pulkit_Jain_
Adobe Employee
Pulkit_Jain_Adobe EmployeeAccepted solution
Adobe Employee
May 2, 2023

@shyamasundar-ks 

I think getResourceResolver() does not create a new ResourceResolver; as a best practice, we recommend using the try-with-resources statement that ensures that each resource is closed at the end of the statement, with the most commonly used way to make a new ResourceResolver i.e ResourceResolverFactory.

More info here- https://cqdump.joerghoh.de/2018/11/14/try-with-resource-or-i-will-never-forget-to-close-a-resource-resolver/