Expand my Community achievements bar.

Dive into Adobe Summit 2024! Explore curated list of AEM sessions & labs, register, connect with experts, ask questions, engage, and share insights. Don't miss the excitement.

Do I need to logout a session that's adapted from a created resolver?

Avatar

Level 1

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?

3 Replies

Avatar

Level 7

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:

Adobe Experience Manager Help | Querying Adobe Experience Manager 6 data using the Sling getServiceR...

We hope this information helps!

Regards,

TechAspect Solutions

Avatar

Employee Advisor

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