I am trying to close the resource resolver that I opened but I got this error “javax.jcr.RepositoryException: This session has been closed when I close resource resolver. Actually I don’t see any problem if you leave the resource resolver as open but I don’t want to leave the resource resolver open in the code.
serviceParam.put(ResourceResolverFactory.SUBSERVICE, "serviceNew");
ResourceResolver resourceResolver = null;
try
{
resourceResolver = resourceResolverFactory.getServiceResourceResolver(serviceParam);
final Configuration configuration = configurationManagerFactory.getConfigurationManager(resourceResolver)
.getConfiguration(cloudConfigurationType.getServiceName(), services);
if (null != configuration)
{
return configuration.getContentResource().adaptTo(ValueMap.class);
}
} catch (LoginException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
} finally
{
if (resourceResolver != null && resourceResolver.isLive())
{
resourceResolver.close();
}
}
Error message:-
org.apache.sling.engine.impl.SlingRequestProcessorImpl service: Uncaught SlingException
java.lang.IllegalArgumentException: javax.jcr.RepositoryException: This session has been closed.
at org.apache.sling.jcr.resource.internal.JcrValueMap.read(JcrValueMap.java:337) [org.apache.sling.jcr.resource:3.0.16]
at org.apache.sling.jcr.resource.internal.JcrValueMap.get(JcrValueMap.java:101) [org.apache.sling.jcr.resource:3.0.16]
Observing many error messages like below in logs If I dont close a resource resolver in code
23.12.2020 11:56:30.481 [Apache Sling Resource Resolver Finalizer Thread] INFO o.a.s.r.i.CommonResourceResolverFactoryImpl Unclosed ResourceResolver was created here:
java.lang.Exception: Opening Stacktrace
at org.apache.sling.resourceresolver.impl.CommonResourceResolverFactoryImpl$ResolverReference.<init>(CommonResourceResolverFactoryImpl.java:540)
The real problem is, session getting closed as soon as we close resource resolver. Is this an issue with AEM code? or Any other way to handle this case?
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…