aspose file tools*
The moose likes EJB Certification (SCBCD/OCPJBCD) and the fly likes @PostConstruct confusion Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » EJB Certification (SCBCD/OCPJBCD)
Bookmark "@PostConstruct confusion" Watch "@PostConstruct confusion" New topic
Author

@PostConstruct confusion

Shankar sanjay
Ranch Hand

Joined: Sep 14, 2009
Posts: 117
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.
Frits Walraven
Creator of Enthuware JWS+ V6
Bartender

Joined: Apr 07, 2010
Posts: 1696
    
  25

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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: @PostConstruct confusion