My resolver is created through ResourceResolverFactory:
resolver = getResolverFactory().getServiceResourceResolver(serviceParams);
I already have a finally block in my method which closes the resolver.
My question is regarding the session I'm using:
Session session = resolver.adaptTo(Session.class);
Do I need to logout this session or not?
Hi,
Yes, you need to release all the resources associated with the Session.
When you open a JCR session, there is a reference to the JCR repository object. Every session will consume some memory unless the logout() method is called explicitly. If you do not call this call and create lots of sessions, you risk an out-of-memory exception by your JVM, which terminates the AEM instance. A single leaked session isn’t a problem, but if you have hundreds or thousands of leaked sessions, it might turn into a problem.
NOTE: session.logout() releases all the resources associated with the Session. This method should be called when a Session is no longer needed.
Session (Content Repository for Java Technology API Version 2.0)
Please refer the below link for an example:
We hope this information helps!
Regards,
Views
Replies
Total Likes
Use AutoCloseable, then you don't have to worry about this.
htl-examples/AutoCloseableService.java at master · heervisscher/htl-examples · GitHub
Hi,
You have to close a session or a resourceresolver only if you opened the session or resourceResolver. In the typical pattern you use as well you login to a resource resolver and then adaptTo() a session.
adaptTo(Session.class) does not open a new session, but just gives you the JCR session hidden inside the resourceresolver. Therefor you don't need to close it. Just don't forget to close the resourceResolver.
Jörg
Views
Replies
Total Likes
Views
Likes
Replies
Views
Likes
Replies
Views
Likes
Replies
Views
Likes
Replies
Views
Likes
Replies