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: Tomcat thread pooling
PostPosted: Mon Mar 26, 2007 3:52 am 
Newbie

Joined: Mon Mar 26, 2007 3:44 am
Posts: 1
I've read the article here:
http://www.theserverside.com/tt/articles/article.tss?l=HibernateTomcat.

And it is said there:

Quote:
The difference between openSession() and getCurrentSession() is that the former, each time it is used, provides a brand new Hibernate Session. That is exactly what we want in our servlet. In contrast, getCurrentSession attempts to associate a Hibernate Session with a specific thread (the Singleton-per-Thread pattern), which Hibernate achieves via the use of an embedded (hidden) ThreadLocal. Unfortunately, Tomcat maintains a thread pool, and re-uses a given thread after a particular Http request is finished with it. Hence a brand new Http request can receive a previously used thread, which already happens to have a Hibernate Session associated with it (via the ThreadLocal), and getCurrentSession() may by chance receive an unrelated Hibernate Session when it ought to receive a brand new one. We may have a new Http session, and logically a new thread, but physically be re-using an existing thread. In this way, Tomcat 5.5.x and Hibernate 3.1 can confuse each other.
.

What do u think about it? Is that problem really exists?

Another problem is:
I'm keeping user profile in ThreadLocal, should i change the place? Will Session suit or maybe even here we have some problems?

I'm using hibernate 3.2.2 and tomcat 5.5.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 06, 2008 11:44 pm 
Newbie

Joined: Fri May 27, 2005 3:19 pm
Posts: 18
I just came across the same article and would like to know if it is in fact true. Is it not Thread safe to use getCurrentSession() with Tomcat connection pool via JNDI.

I am not surer what exactly is cached by Tomcats connection pool that can mess with Hibernate getCurrentSession, sounds a bit off? Anyone?


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.