• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Using EJB's from Action method - is this safe?

 
Ranch Hand
Posts: 124
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have an Action class that calls methods on an EJB (stateless session bean acting as session facade).

To improve performance I'm thinking to store the reference to the EJB object (i.e stub) as an instance variable like so -

public class TestAction extends Action
{
EJB1Local oEJB1 = null;

public TestAction ()
{
EJB1LocalHome home = ... get home object
oEJB1 = homeDataEngine.create();
}

then when each time the action's called do this -

public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception
{
oEJB1.method1(........);
oEJB1.method1(........);
}

I can't determine from the EJB doc's if this is safe or not - should I just be storing the home ref (EJB1LocalHome) & doing a .create everytime before I want to use it or what?

Any ideas?

Hopefully I've explained it ok?

thanks

harry
 
Ranch Hand
Posts: 327
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can't use the same EJBObject in multiple threads at the same time. Like you said, you should cache only the EJBHome object and call create() every time your action is executed. Better yet, you could use the Service Locator design pattern to cache your EJBHome references in one centralized location.
 
A Harry
Ranch Hand
Posts: 124
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for that Anthony, makes sense the way you put it!
reply
    Bookmark Topic Watch Topic
  • New Topic