Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
BedrockMission!

Learn More

View all

Sign in to view all badges

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

Avatar

Avatar
Boost 1
Level 1
carlos71224838
Level 1

Like

1 like

Total Posts

1 post

Correct Reply

0 solutions
Top badges earned
Boost 1
View profile

Avatar
Boost 1
Level 1
carlos71224838
Level 1

Like

1 like

Total Posts

1 post

Correct Reply

0 solutions
Top badges earned
Boost 1
View profile
carlos71224838
Level 1

04-05-2018

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?

Replies

Avatar

Avatar
Boost 50
Level 6
Techaspect_Solu
Level 6

Likes

63 likes

Total Posts

150 posts

Correct Reply

79 solutions
Top badges earned
Boost 50
Boost 5
Boost 3
Boost 25
Boost 10
View profile

Avatar
Boost 50
Level 6
Techaspect_Solu
Level 6

Likes

63 likes

Total Posts

150 posts

Correct Reply

79 solutions
Top badges earned
Boost 50
Boost 5
Boost 3
Boost 25
Boost 10
View profile
Techaspect_Solu
Level 6

04-05-2018

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

Avatar
Give Back 50
Employee
Feike_Visser1
Employee

Likes

247 likes

Total Posts

970 posts

Correct Reply

221 solutions
Top badges earned
Give Back 50
Give Back 5
Give Back 3
Give Back 25
Give Back 10
View profile

Avatar
Give Back 50
Employee
Feike_Visser1
Employee

Likes

247 likes

Total Posts

970 posts

Correct Reply

221 solutions
Top badges earned
Give Back 50
Give Back 5
Give Back 3
Give Back 25
Give Back 10
View profile
Feike_Visser1
Employee

04-05-2018

Use AutoCloseable, then you don't have to worry about this.

htl-examples/AutoCloseableService.java at master · heervisscher/htl-examples · GitHub

Avatar

Avatar
Coach
Employee
Jörg_Hoh
Employee

Likes

1,087 likes

Total Posts

3,121 posts

Correct Reply

1,063 solutions
Top badges earned
Coach
Give back 600
Ignite 5
Ignite 3
Ignite 1
View profile

Avatar
Coach
Employee
Jörg_Hoh
Employee

Likes

1,087 likes

Total Posts

3,121 posts

Correct Reply

1,063 solutions
Top badges earned
Coach
Give back 600
Ignite 5
Ignite 3
Ignite 1
View profile
Jörg_Hoh
Employee

04-05-2018

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