-->
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.  [ 6 posts ] 
Author Message
 Post subject: Thread Local Session pattern and static fields
PostPosted: Mon Nov 24, 2003 10:52 am 
Regular
Regular

Joined: Mon Oct 06, 2003 1:59 am
Posts: 52
Hi Folks,

is it really a good idea to put the ThreadLocal instance in a static field. Couldn't this be problematic in a clustered J2EE container?

Thx
Toby

_________________
"Wisest of the Maia was Ol


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 24, 2003 10:55 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
eh?


I'm trying to think what you might mean by this .... how would clustering affect anything?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 25, 2003 2:51 am 
Regular
Regular

Joined: Mon Oct 06, 2003 1:59 am
Posts: 52
gavin wrote:
eh?


I'm trying to think what you might mean by this .... how would clustering affect anything?


A single JVM ensures that a static field is only loaded once by the classloader. This is differnt in a J2EE Container. First of all you have different class loaders per JVM. But this is okay as each classloader is responsible for a single application and in most cases you can silgthly ignore this (if you use reflection you should load classes with correct classloader). The problem is distrubted programming and clustering. Normally containers use something build on top of JINI/RMI/Serialization to replicate the JVM heap to each cluster note. As clustering is only a matter of configuration from view of container and deployer you have to ensure that your code works as it should in a clustered, replicated environment. Having said this the single JVM gurantee of a classic member is not longer valid for a clustered mulit-JVM environment. Of course maybe we need a real clusterable VM that ensures static to be static but I cannot imagine that is is planed by Sun or any other JCP member.

In EJB spec static fields are forbidden due to the restriction of the replicated, clustered nature of J2EE containers. Singletons are another example for this. You should at least synchronize them into a mulit-classloader architecture but synchronized is not allowed into a EJB Container (but in a servelt container you should have no problems with it).

My intention is not to meet trouble halfway! I want is to be carefully, thats everything.

Any thougths, hints, stuff, advice, wisdom abouth this?

_________________
"Wisest of the Maia was Ol


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 25, 2003 8:01 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
But this is a thread local! A thread is local to a JVM by definition.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 25, 2003 9:54 am 
Regular
Regular

Joined: Mon Oct 06, 2003 1:59 am
Posts: 52
gavin wrote:
But this is a thread local! A thread is local to a JVM by definition.


Maybe I'm to sensiblized and I seeing ghosts. Sorry.

_________________
"Wisest of the Maia was Ol


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 25, 2003 10:01 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
The purpose of thread loacl is to share an object for the whole thread. This is very useful in J2EE env since EJBs work by thread, an http session either.
Thus this is a convenient way to share the same session object for 1 user tx (no concurrent issue). This isn't a way to share data accross JVMs.

_________________
Emmanuel


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