Expand my Community achievements bar.

SOLVED

Closing sessions in Servlets and Workflows requrired?

Avatar

Former Community Member

Hi,

In our application, we have a lot of servlets and workflows that run on continuously. We were thinking of using sessions as we need to update the JCR. 

From the servlet we can get the sessions like slingRequest.getResourceResolver.adapTo(Session.class) and in the workflow we already have a session in the method signature if the class implements WorkflowProcess or something.

Do we need to explicitly close these session or sling engine will close these session for us once we the code goes out of scope for the method.

Any help is appreciated.

Thanks.

1 Accepted Solution

Avatar

Correct answer by
Employee

kumarlal123 wrote...

Sham HC wrote...

kumarlal123 wrote...

justin_at_adobe wrote...

bsloki wrote...

Hi Kumar,

We need to close the session in both the scenarios which you have mentioned.

 

No.... closing a Session (or ResourceResolver) which your code didn't create would have significant consequences. Like Feike said - only close what you open.

 

    Is slingRequest.getResourceResolver().adaptTo(Session.class) same as slingRepository.loginAdmin(null)? 

Lastly, how many concurrent sessions can we have in Author and Publisher instances (any rough ideas?)

Both session are different.   adoptTo(Session.class)  is dynamic & returns the session of user.  Where as loginAdmin always returns a session to the default workspace which has administrative powers.  

There is no limit of concurrent sessions but if more than 100 at given point of time then some thing not properly implemented. AEM tested under heavy load with tough tool not consumed more than 43.   Refer [1] to identify such issue.

[1]   http://helpx.adobe.com/experience-manager/kb/AnalyzeUnclosedSessions.html

 

Hi Sham,

Yes, you are right that request will give use the user session and the other will give admin session. I did not phrased my question right it seems like. What i wanted to ask was that if i get a session out of request object, do i have to close it? I know it has been iterated above that i do, but i don't seem to understand why i need to close the session as it was an adaptation essentially and i was not opening a session explicitly. 

Same goes with the workflow sessions as they are injected by the workflow process, why do i close it. If i am not using that session, i am not closing it but if i do why do i need to close it?

 

Sorry to use all caps here, but..

DO NOT CLOSE THE SESSION FROM THE REQUEST OBJECT OR THE WORKFLOW PROCESS. ONLY CLOSE A SESSION OR RESOURCERESOLVER IF YOU OPEN IT.

View solution in original post

9 Replies

Avatar

Employee

Only if you "create" a session you the close(logout) it.

Same for a resourceResolver, only close it if you have created it.

Avatar

Level 10

Hi Kumar,

We need to close the session in both the scenarios which you have mentioned.

Avatar

Employee

bsloki wrote...

Hi Kumar,

We need to close the session in both the scenarios which you have mentioned.

 

No.... closing a Session (or ResourceResolver) which your code didn't create would have significant consequences. Like Feike said - only close what you open.

Avatar

Former Community Member

justin_at_adobe wrote...

bsloki wrote...

Hi Kumar,

We need to close the session in both the scenarios which you have mentioned.

 

No.... closing a Session (or ResourceResolver) which your code didn't create would have significant consequences. Like Feike said - only close what you open.

 

Hi Justin,

Is slingRequest.getResourceResolver().adaptTo(Session.class) same as slingRepository.loginAdmin(null)? The reason i am asking it is because in the first case i am getting the session out of request and engine might be clearing everything out from the request variable once the request is performed. 

Same is in the case of Workflows. In workflows sessions are injected automatically and should be cleared automatically. I know if i manually create a session i need to close it.

Lastly, how many concurrent sessions can we have in Author and Publisher instances (any rough ideas?)

Thanks in advance.

Avatar

Level 10

kumarlal123 wrote...

justin_at_adobe wrote...

bsloki wrote...

Hi Kumar,

We need to close the session in both the scenarios which you have mentioned.

 

No.... closing a Session (or ResourceResolver) which your code didn't create would have significant consequences. Like Feike said - only close what you open.

 

    Is slingRequest.getResourceResolver().adaptTo(Session.class) same as slingRepository.loginAdmin(null)? 

Lastly, how many concurrent sessions can we have in Author and Publisher instances (any rough ideas?)

Both session are different.   adoptTo(Session.class)  is dynamic & returns the session of user.  Where as loginAdmin always returns a session to the default workspace which has administrative powers.  

There is no limit of concurrent sessions but if more than 100 at given point of time then some thing not properly implemented. AEM tested under heavy load with tough tool not consumed more than 43.   Refer [1] to identify such issue.

[1]   http://helpx.adobe.com/experience-manager/kb/AnalyzeUnclosedSessions.html

Avatar

Former Community Member

Sham HC wrote...

kumarlal123 wrote...

justin_at_adobe wrote...

bsloki wrote...

Hi Kumar,

We need to close the session in both the scenarios which you have mentioned.

 

No.... closing a Session (or ResourceResolver) which your code didn't create would have significant consequences. Like Feike said - only close what you open.

 

    Is slingRequest.getResourceResolver().adaptTo(Session.class) same as slingRepository.loginAdmin(null)? 

Lastly, how many concurrent sessions can we have in Author and Publisher instances (any rough ideas?)

Both session are different.   adoptTo(Session.class)  is dynamic & returns the session of user.  Where as loginAdmin always returns a session to the default workspace which has administrative powers.  

There is no limit of concurrent sessions but if more than 100 at given point of time then some thing not properly implemented. AEM tested under heavy load with tough tool not consumed more than 43.   Refer [1] to identify such issue.

[1]   http://helpx.adobe.com/experience-manager/kb/AnalyzeUnclosedSessions.html

 

Hi Sham,

Yes, you are right that request will give use the user session and the other will give admin session. I did not phrased my question right it seems like. What i wanted to ask was that if i get a session out of request object, do i have to close it? I know it has been iterated above that i do, but i don't seem to understand why i need to close the session as it was an adaptation essentially and i was not opening a session explicitly. 

Same goes with the workflow sessions as they are injected by the workflow process, why do i close it. If i am not using that session, i am not closing it but if i do why do i need to close it?

Avatar

Correct answer by
Employee

kumarlal123 wrote...

Sham HC wrote...

kumarlal123 wrote...

justin_at_adobe wrote...

bsloki wrote...

Hi Kumar,

We need to close the session in both the scenarios which you have mentioned.

 

No.... closing a Session (or ResourceResolver) which your code didn't create would have significant consequences. Like Feike said - only close what you open.

 

    Is slingRequest.getResourceResolver().adaptTo(Session.class) same as slingRepository.loginAdmin(null)? 

Lastly, how many concurrent sessions can we have in Author and Publisher instances (any rough ideas?)

Both session are different.   adoptTo(Session.class)  is dynamic & returns the session of user.  Where as loginAdmin always returns a session to the default workspace which has administrative powers.  

There is no limit of concurrent sessions but if more than 100 at given point of time then some thing not properly implemented. AEM tested under heavy load with tough tool not consumed more than 43.   Refer [1] to identify such issue.

[1]   http://helpx.adobe.com/experience-manager/kb/AnalyzeUnclosedSessions.html

 

Hi Sham,

Yes, you are right that request will give use the user session and the other will give admin session. I did not phrased my question right it seems like. What i wanted to ask was that if i get a session out of request object, do i have to close it? I know it has been iterated above that i do, but i don't seem to understand why i need to close the session as it was an adaptation essentially and i was not opening a session explicitly. 

Same goes with the workflow sessions as they are injected by the workflow process, why do i close it. If i am not using that session, i am not closing it but if i do why do i need to close it?

 

Sorry to use all caps here, but..

DO NOT CLOSE THE SESSION FROM THE REQUEST OBJECT OR THE WORKFLOW PROCESS. ONLY CLOSE A SESSION OR RESOURCERESOLVER IF YOU OPEN IT.

Avatar

Level 10

kumarlal123 wrote...

 

Yes, you are right that request will give use the user session and the other will give admin session. I did not phrased my question right it seems like. What i wanted to ask was that if i get a session out of request object, do i have to close it?

 

For adaptTo example given above The session will be closed automatically by the framework