Win a copy of liveProject: Protecting User Data with Spring Security and OAuth2 this week in the Spring 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:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • paul wheaton
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Liutauras Vilda
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Piet Souris
Bartenders:
  • salvin francis
  • Mikalai Zaikin
  • Himai Minh

@PostConstruct confusion

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

I am using EJB stateless session bean, due to some reason,we want to INITIALIZE database connection or database resource lookup(datasource) in @PostContruct method.

My understanding is that the ejb container will decide to create new EJB Bean whenever number of calls from clients goes high (correct me if i am wrong), now doubt is that each instance will invoke @PostContruct method? or only the very first bean invoke @PostContruct method.

if each bean instance will invoke @PostContrct method then we will be looking datasource (jndi look) redundantly.
 
Creator of Enthuware JWS+ V6
Posts: 3390
311
Android Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Shankar,

now doubt is that each instance will invoke @PostContruct method?


Yes, the PostConstruct method will run for every instance.

In EJB 3.1 you could use the @Singleton EJB (with an @Startup annotation)

Regards,
Frits
 
Eat that pie! EAT IT! Now read this tiny ad. READ IT!
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
reply
    Bookmark Topic Watch Topic
  • New Topic