Help coderanch get a
new server
by contributing to the fundraiser
  • 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
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Carey Brown
  • Mikalai Zaikin
Bartenders:
  • Lou Hamers
  • Piet Souris
  • Frits Walraven

are stateless beans thread safe

 
Ranch Hand
Posts: 116
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am being lazy here - but as I have started reading about EJB some questions come up .

So before I lose track of what doubts I have - I thought would place them here .

So this is an excuse in advance if some one tells me that I am asking them to do my homework !

Are stateless beans threadsafe ?
How does the container go about it ? after the bean is picked from pool - can container use same bean to process multiple requests ?

I am assuming that stateful beans ( since they are per client ) would remain available specific to a client and thereby there cannot be any issues regarding thread safety in case of steful session beans ?

Thanks ,
~satish
[ August 01, 2008: Message edited by: satish bodas ]
 
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, EJBs are threadsafe.
 
satish bodas
Ranch Hand
Posts: 116
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Paul
 
author
Posts: 4342
40
jQuery Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I agree with Paul although I think you can make them not thread safe by spawning your own threads, granted in J2EE spawning threads is a really bad idea.
 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What is a thread-saftiness? If an object is shielded by another object( proxy or container) which serializes concurrent threads, does it make the first object itself thread-safe?

Why in EJB 1.1. and EJB 2.0 it was always highly recommended not to share reference to an EJB among client's threads?

It is used to belive that Entity Beans are thread-safe. Hwo is controlling concurrent access to independent Load and Store methonds? To me, if it is a container, then the Entity Bean itself is NOT thread safe.

In general, I think that from the performace persective, it makes sense to have EJB not thread safe becuase EJB Container can do this job for EJBs. I need to look into EJB 3.0 - how POJO resolves this issue.
 
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Scott Selikoff wrote:I agree with Paul although I think you can make them not thread safe by spawning your own threads, granted in J2EE spawning threads is a really bad idea.



Does that include the case where you inject a stateless EJB in a ServletContextListener with

@EJB FooLocal fooLocal;

and pass it as a parameter to a spawned thread (which has to do some ansynchronous tasks):

MaintencanceThread maintencanceThread = new MaintenanceThread(fooLocal);
t = new Thread(maintenanceThread);
t.setDaemon(false);
t.start();


 
Paul Sturrock
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You are not spawning a thread from the EJB there. That is the part that is specifically precluded by the EJB specification.
 
Per Lindberg
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok, Paul, that's right.

But now suppose that this maintenance thread listens to a ServerSocket for TCP connect requests, and then spawns new threads (using an Executor). Now these threads would all use the same instance of the stateless session bean. That wouldn't be thread-safe, right?

 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic