File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes EJB and other Java EE Technologies and the fly likes A Question about The Life Cycle of a Stateless Session Bean Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "A Question about The Life Cycle of a Stateless Session Bean" Watch "A Question about The Life Cycle of a Stateless Session Bean" New topic
Author

A Question about The Life Cycle of a Stateless Session Bean

kong song
Greenhorn

Joined: May 12, 2009
Posts: 13
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

Joined: Jul 20, 2005
Posts: 9953
    
163

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


[My Blog] [JavaRanch Journal]
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: A Question about The Life Cycle of a Stateless Session Bean
 
Similar Threads
EJB3 mock questions available now! (Section 2)
Doubt from the Specs
Error in EJB 3.0 core specification?
How to define some mehod for global resource initializtion and recycle in JBoss container!
Bean Things are confusing !!