Win a copy of Rust Web Development this week in the Other Languages forum!
  • 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
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

global initialization for all EJB

 
Ranch Hand
Posts: 137
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

There is something in JSP world which EJB does not have, one of them is a place for initialization before any EJB runs.

Servlet has that via a ServletContextListener, in which I can place code and store objects as attributes so that they are available to all servlets and JSPs in my web app. That is done before ANY servlet runs. This could be useful for a global object like DataSource reference, etc.

I do not find such equivalence in EJB world, there is no global EJBContext object like the global ServletContext. And there is not a place for a global initialization before EJB runs.

What are the reasons that EJB does not have that?

Thanks.
Yan
 
Yan Zhou
Ranch Hand
Posts: 137
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
here is what I thought,

Servlet and JSP can make up a real Web Application.

EJBs by themselves donot make up a real app., and therefore the things apply to an app. does not apply to EJB, after all, EJBs are all about components.
 
author & internet detective
Posts: 40913
840
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yan,
EJBs could be the only J2EE components in an app though. You could have an application client or just make remote calls.

In this case, you would use a static variable in a class or better yet, a singleton for those global resources. It would be initialized on first access.
 
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes. The big difference is that web app is application and EJB is just component. EJBs should be less coupled as possible. Think about EJB as some module which does it own job. Of cource, you can have references to other EJBs or resources. But if you created some related context, they wuold be very coupled which is bad.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic