• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Tim Cooke
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Frank Carver
  • Henry Wong
  • Ron McLeod
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Himai Minh

is ThreadLocal devil in clustering environment?

 
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm not quite familiar with ThreadLocal class. What I need to do is pass a parameter to all methods in all service classes. So it become good candidate to use ThreadLocal to save this context info. However it is suggested in the office that ThreadLocal should be absolutely forbid in clustering j2EE application server environment due to the "clustering". Anyone have argument to support or against this statement?
 
author and iconoclast
Posts: 24204
44
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"Clustering" refers to running an application on multiple machines for capacity purposes. J2EE has some elaborate mechanisms built in that allow objects to be transparently migrated from one machine to another in a cluster. Any dependence on the specific JVM in which an object lives -- such as using static variables, or ThreadLocals (which are effectively another kind of global variable) -- breaks these mechanisms. Don't do it.
 
Will Lee
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you Ernest very much for the reply. It's very helpful for my design.
 
Will Lee
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I've been given a thought over weekend. And I'm still a bit confused. Since all the methods call in my application is invoked by one request from browser, therefore these methods invocation should live and die w/ the thread w/in the single JVM. This thread for servlet request will never propagate across the cluster. Why can't use threadLocal?

I'm not use ThreadLocal to save class level object, I just want it to keep the method context (not session context or anything else) so that my next method w/in same thread will get it. Therefore I don't have to pass this context to all my methods. Is is feasible?
 
reply
    Bookmark Topic Watch Topic
  • New Topic