-->
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.  [ 4 posts ] 
Author Message
 Post subject: About using ThreadLocal
PostPosted: Tue Nov 18, 2003 5:24 pm 
Beginner
Beginner

Joined: Tue Sep 09, 2003 5:28 pm
Posts: 33
Location: Cincinnati, OH
Hi there,

I am going to implement a web application using Hibernate, and I'll create a servlet for controlling. I am not sure if I need to use ThreadLocal to handle the session? I am a bit confused; anyone knows when we are supposing to use ThreadLocal?


Thanks a lot!


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 18, 2003 5:40 pm 
Regular
Regular

Joined: Tue Sep 16, 2003 11:35 am
Posts: 93
Location: San Francisco, CA
You probably need to use a ThreadLocal if your web app is threaded (which is almost certainly is). SessionFactory is thread safe but Session is not so each thread must have its own Session. A good way to ensure this is with ThreadLocal. I think the wiki explains this pretty well.


Top
 Profile  
 
 Post subject: Re: About using ThreadLocal
PostPosted: Tue Nov 18, 2003 8:04 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
xinxin wrote:
I am going to implement a web application using Hibernate, and I'll create a servlet for controlling. I am not sure if I need to use ThreadLocal to handle the session? I am a bit confused; anyone knows when we are supposing to use ThreadLocal?

Threadlocal variables are a convinient way to get the power of singleton model wo having it's drawbacks:
* you can access threaded variable easily
* no synchro needed (neither scalability issues) since you use it in the same thread

This roll for 2+ tiers applications

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 20, 2003 10:30 am 
Beginner
Beginner

Joined: Tue Sep 09, 2003 5:28 pm
Posts: 33
Location: Cincinnati, OH
Thank you guys for the reply!

I will try to use ThreadLocal, and hope it works for me!

Thanks


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