• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

@PostConstruct confusion

 
Shankar sanjay
Ranch Hand
Posts: 117
  • Mark post as helpful
  • send pies
  • 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.
 
Frits Walraven
Creator of Enthuware JWS+ V6
Saloon Keeper
Pie
Posts: 2345
90
Android Chrome Eclipse IDE
  • Mark post as helpful
  • send pies
  • 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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic