• 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:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Junilu Lacar
  • Liutauras Vilda
Sheriffs:
  • Paul Clapham
  • Jeanne Boyarsky
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
Bartenders:
  • Jesse Duncan
  • Frits Walraven
  • Mikalai Zaikin

Session bean methods thread safe (?!)

 
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 know this must be so.I know this is a weird question to ask , but nevertheless I ask. Will all stateless session-bean methods be thread safe and only serviced by one client at a time ?

But we cannot say the same of a util java class method this bean/active beans of different clients may call inbetween right ... Debugging ... Synchronized ...

Okay I am checking something that smells and sounds "concurrency" that I can never reproduce in my box but user incidents of such occurances in production let me believe something otherwise ...

Thanks
Lakshmi

[ May 24, 2005: Message edited by: Laksh Anan ]
[ May 24, 2005: Message edited by: Laksh Anan ]
 
Ranch Hand
Posts: 704
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Laksh,

The bean thread safe basically means that each client talks to a different bean instance. Hence if your bean has an attribute of some simple data type like an integer and one client increments that integer, the changes are visible only to that client. Compare this very simple example with a servlet and you�ll notice the contrary: one needs to synchronize the data access in the servlet itself, since multiple clients might share the same servlet instance (this is why defining attribute instances in servlets is a bad practice, but not with ejbs).
However if the instance attribute is a singleton or your beean accesses a static class, then the story will get little bit more complicated. In this case all bean instances will share the same unique object and the singleton/static class needs to be design thread safe.
Regards.
 
Lakshmi Anantharaman
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks, I really appreciate it.
I see what may be the problem still have more questions

If a static utility class static method (which does not have any instance/class variable ) when 2 thread enter the method have their own local copies of method arguments , so will each thread will have its own context or is it still possible that the thread that comes in later may overwrite the local method arguments for he earlier thread , While I am going to test this ... I thought I should ask in case I conclude wrongly that without instance variables everything is actually thread safe.

Is there like a thread forum here ?!
[ May 24, 2005: Message edited by: Lakshmi Anantharaman ]
 
Lakshmi Anantharaman
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There is a Threads forum and each thread in a method have its own local copies of local variable/args inside a method its only the shared objects that will need to be made expicitly thread-safe

Thanks Anyway
Lakshmi
 
pie. tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic