This is probably a silly question, but in what cases does a developer actually have to call close() on a ResourceResolver instance?
I keep reading that this is necessary [1] [2], but when using WCMUse's getResourceResolver() helper function in AEM6 it doesn't seem to be necessary any more. We also have some cases where we get the RR from the request and this would break the site because it prematurely closes the resource resolver:
ResourceResolver resourceResolver = getResourceResolver(); resourceResolver.close();
Solved! Go to Solution.
Views
Replies
Total Likes
Hi,
no, request.getResourceResolver() or request.adaptTo(ResourceResolver.class) do not create a new ResourceResolver.
The most used way to create a new ResourceResolver is using the ResourceResolverFactory.
kind regards,
Jörg
Views
Replies
Total Likes
you should be responsible to close the resourceResolver session which is initiated by you. You can make sure that you close your RR session using 'finally' block
Views
Replies
Total Likes
Follow the rule "You open a resourceResovler / Session, You Close it".
If this is not the case, leave it...
Views
Replies
Total Likes
OK, thanks. So just to confirm, "getResourceResolver()" or adaptTo(ResourceResolver.class) would not actually create a new instance, right? What's an example of a manually created ResourceResolver (factory?)?
Views
Replies
Total Likes
Hi,
no, request.getResourceResolver() or request.adaptTo(ResourceResolver.class) do not create a new ResourceResolver.
The most used way to create a new ResourceResolver is using the ResourceResolverFactory.
kind regards,
Jörg
Views
Replies
Total Likes
Typically, any code in which a resource resolver is not tied to a request, you will need to create/close.
So, for example, if you have a service running in the background; one thats maybe on a schedule.
There's no request whose resource-resolver you can re-use, so you create one manually directly from the factory for use by this service.
You will be responsible for closing this resource resolver/session.
Views
Replies
Total Likes
Views
Likes
Replies
Views
Likes
Replies