Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

A Question about The Life Cycle of a Stateless Session Bean

 
kong song
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As We know the bean class may define one @PostConstruct method,
When the EJB server is first started, it may create a number of stateless bean instances and enter them into the Method-Ready Pool.
My Question is that when I define a PostConstruct method in stateless bean, Does this method is invoked for each instance?
in the other words, If I define PostConstruct method for some global resource initialization which should be executed only once, does container call this mehod by each instance more than once?

after all,How can I define some method for initializing global resource and container just only call once? and How about recycle such resource only when the container is closing.

Thanks!
 
Jaikiran Pai
Marshal
Pie
Posts: 10447
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
kong song wrote:As We know the bean class may define one @PostConstruct method,
When the EJB server is first started, it may create a number of stateless bean instances and enter them into the Method-Ready Pool.
My Question is that when I define a PostConstruct method in stateless bean, Does this method is invoked for each instance?


Yes, @PostConstruct is per instance of the bean.

kong song wrote:
after all,How can I define some method for initializing global resource and container just only call once? and How about recycle such resource only when the container is closing.

Thanks!

Let's continue this second question in your other thread here
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic