-->
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.  [ 2 posts ] 
Author Message
 Post subject: threadlocal session concept and web application
PostPosted: Wed Apr 05, 2006 8:22 am 
Newbie

Joined: Wed Jan 18, 2006 2:19 pm
Posts: 14
Hi, I have some bean with application logic
Code:
public class MyClass{
  ...
  public void myMethod(){
    try{
        session=HibUtil.currentSession();
         ...
    }catch (HibernateException ex){
    }finally{
        HibUtil.closeSession();
    }
  }
   
}

where class HibUtil manages a thread local session.

When I start a web application, I create a MyClass instance and save it to application context. I have several struts actions, where I always take the instance from app. context and call its myMethod. I'd like to ask whether new threadlocal session is created every time i call action in struts or not..

The problem is that when I call another method from myMethod, I don't won't to close session in the inner method. So I can create new threadlocal variable which counts a depth of nesting and close session only if the depth is 0.
But I don't know whether sessions won't mix when some struts action is called many times at the same time..


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 05, 2006 8:43 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 7:19 pm
Posts: 2364
Location: Brisbane, Australia
I assume you using the Hibernate utility class that was documented in HIA.
In anycase, threadlocal pattern (see wiki) uses a ThreadLocal and if the execution is using the same thread then the same session will be returned.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 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.