Hi,
In AEM 6.1, we do not have to close the resolver if we are getting resource resolver from sling request or workflow session.
But in an OSGI component if we are getting the ResourceResolver from ResourceResolverFactory as below
@Reference
ResourceResolverFactory rrf;
...
public String getData() {
ResourceResolver rr = null;
Map<String, Object> param = ...
param.put(ResourceResolverFactory.SUBSERVICE, "sub-service");
try {
rr = rrf.getServiceResourceResolver(param);
...
}
...
}
Do we have to close the resolver?
Solved! Go to Solution.
if you open it, you are responsible for closing it
if you use a reference to the resourceResolver, then it is not your responsibility to close it
resourceResolver
FROM a request or workflow session, you did not open the resolver and you do not need to close it.More info
Thanks
Arun
Hello Radha,
Yes, it is recommended to always close it via ResourceResolver.close()
if(resourceResolver != null && resourceResolver.isLive())
{
resourceResolver.close();
}
if you open it, you are responsible for closing it
if you use a reference to the resourceResolver, then it is not your responsibility to close it
resourceResolver
FROM a request or workflow session, you did not open the resolver and you do not need to close it.More info
Thanks
Arun
Thanks arunp99088702 Vish.dhaliwal for your inputs.
But in most of the community articles which gets resource resolver(rr) as above, either they mention a note about closing rr or use administrative rr. I think the new articles should stop using the old approach. This would help the people who are new to AEM community.
Views
Replies
Total Likes
We agree - new ones will always show this way.
Map<String, Object> param = new HashMap<String, Object>();
param.put(ResourceResolverFactory.SUBSERVICE, "datawrite");
ResourceResolver resolver = null;
try {
//Invoke the adaptTo method to create a Session used to create a QueryManager
resolver = resolverFactory.getServiceResourceResolver(param);
As shown here in this recent 6.4 community article: Scott's Digital Community: Querying Adobe Experience Manager 6.4 JCR data
Views
Replies
Total Likes
smacdonald2008 Should the resource resolver be closed or get it using try-with-resources (AEM 6.2 onwards)?
Views
Replies
Total Likes
Hi Radha,
Scott is right.
It is recommended that to use the Sling mapping to get the resolver.
Thanks,
Ratna Kumar.
Views
Replies
Total Likes
Ratna Kumar Yes Scott has shown how to get the resolver in an OSGI component. But the article is not showing how to close it.
Views
Replies
Total Likes
I dont think you need to close it. ResourceResolver is Autoclosable.
ResourceResolver ("The Adobe AEM Quickstart and Web Application.")
Views
Replies
Total Likes