• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Paul Clapham
  • Bear Bibeault
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Jj Roberts
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • salvin francis
  • Scott Selikoff
  • fred rosenberger

Thred Safety when Injecting an EJB into servlet using @EJB

 
Ranch Hand
Posts: 2234
Eclipse IDE Firefox Browser Redhat
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Hi , i have read that

when EJBs were injected into servlets using @EJB it is said that there will be no Thread Safety here ??

Is this true.
 
author & internet detective
Posts: 40239
819
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes. Just like any other instance variable in a servlet.
 
Ravi Kiran Va
Ranch Hand
Posts: 2234
Eclipse IDE Firefox Browser Redhat
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you very much .
Then is the jndi lookup is the appropiate way to call a Bean from Servlet ??
 
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why isn´t it thread-safe??
Is not the EJB container responsible for assigning an available bean instance to every client (in our case, the servlet)? I think the EJB container assures you that the ejb instance won't be used by anybody else as long as you hold the reference....
 
Ranch Hand
Posts: 276
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Manuel Alberto Quero wrote:Why isn´t it thread-safe??



Because a single instance of the servlet will process all the requests coming from different threads.
 
Manuel Alberto Quero
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OK Lorand, thanks...

The I think that the answer to the question of Ravi Kiran V:
"Then is the jndi lookup is the appropiate way to call a Bean from Servlet ??"

Is yes (for stateful session beans), but without caching the reference. So every time you execute the servlet you need to perform:

ejb = (ExampleStatefulSession)ctx.lookup("EnterpriseApp/ExampleStatefulSession");

Regards
 
You have to be odd to be #1 - Seuss. An odd little ad:
the value of filler advertising in 2020
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic