-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: In a webapp, where to put the Session
PostPosted: Mon Jan 09, 2012 4:24 am 
Newbie

Joined: Mon Sep 07, 2009 4:20 pm
Posts: 12
Hello,

I have a mid-sized webapp (MVC with Servlets and Jsps).

I used to create a new Hibernate session for each request (sometimes several per request) and close them as soon as I was done with the work for this particular session.

Since this can not be good for performance, I was thinking about 2 other ways to handle the Session.

- Put it in the global Application-Scope
- Put it in the Http-Session-Scope

Is there any general advice on when to create a new session in MVC webapps ? The per-request way certainly is overkill, and in my quest for performance, I want to change this.

Best regards,
Yves


Top
 Profile  
 
 Post subject: Re: In a webapp, where to put the Session
PostPosted: Mon Jan 09, 2012 9:33 am 
Expert
Expert

Joined: Wed Mar 03, 2004 6:35 am
Posts: 1240
Location: Lund, Sweden
I would say that you are doing the correct thing already with a session-per-request pattern. This is the recommended approach and sessions are cheap enough to create. You don't say what kind of performance problems you are experiencing but I would expect that there are other (and better) ways to solve them.

An Application-scoped session will not work since a session is not thread-safe.

A Http-Session-scoped session can be used, but only for a limited time. For example, when going through a wizard-like process that is expected to be completed in a relatively short time-frame (session-per-conversation pattern). Keeping the session around longer is likely to result in problems with stale data in the session cache.


Top
 Profile  
 
 Post subject: Re: In a webapp, where to put the Session
PostPosted: Thu Jan 12, 2012 5:20 am 
Newbie

Joined: Mon Sep 07, 2009 4:20 pm
Posts: 12
nordborg wrote:
I would say that you are doing the correct thing already with a session-per-request pattern. This is the recommended approach and sessions are cheap enough to create. You don't say what kind of performance problems you are experiencing but I would expect that there are other (and better) ways to solve them.

An Application-scoped session will not work since a session is not thread-safe.

A Http-Session-scoped session can be used, but only for a limited time. For example, when going through a wizard-like process that is expected to be completed in a relatively short time-frame (session-per-conversation pattern). Keeping the session around longer is likely to result in problems with stale data in the session cache.


Hey nordborg,

thanks for your explanations. I will just stay with the session-per-request pattern.

Best regards,
Yves


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.