-->
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: Code in a Session is executed in a Thread?
PostPosted: Tue Oct 07, 2008 11:11 am 
Beginner
Beginner

Joined: Tue Aug 26, 2008 4:24 pm
Posts: 29
When I do the next:
Session sesion=factory.openSession();
......code.....
sesion.flush();
sesion.close();

1. The code since I open a Session until I close it, is executed in a java Thread?

Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 07, 2008 4:20 pm 
Expert
Expert

Joined: Mon Nov 26, 2007 2:29 pm
Posts: 443
The code you indicate will be executed in as many threads as there are, at any given time, accessing that code simultaneously.

Hopefully, only one, but there is no guarantee.

In other words, the code you describe is not thread safe.

If you have the reasonable expectation that the session code might be accessed by more than one thread at a time, then it is your responsibility to make it thread safe (no Hibernate configuration trick helps you here) .

Or, at the very least, make it short and stateless enough as to reduce the chance of concurrent access.

_________________
Gonzalo Díaz


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.