Win a copy of Fixing your Scrum this week in the Agile 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
  • Ron McLeod
  • Paul Clapham
  • Rob Spoor
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Junilu Lacar
  • Tim Cooke
Saloon Keepers:
  • Tim Holloway
  • Piet Souris
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Frits Walraven
  • Himai Minh

Many @PostConstruct methods?

 
Ranch Hand
Posts: 383
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi. Can a bean have many @PostConstruct methods? I creted 2, but the container always invokes only one of them (the second one defined in the file, glasssfish v2). The same for @PreDestroy. However, the specs say:

The container then calls the PostConstruct lifecycle callback interceptor method(s) for the bean, if any.


How is it, then?
Thanks.
 
Ranch Hand
Posts: 342
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There can be at most one lifecycle callback method per lifecycle event in a class.
The following classes can contain lifecycle callback methods:

- interceptor classes and their superclasses
- bean classes and their superclasses

If a lifecycle event occurs at first the lifecycle callback methods in the interceptor classes
(and their superclasses) are called and afterwards the lifecycle callback method in the
bean class (and those in the superclasses of the bean class).

For more details concerning the invocation order and overriding see core spec 12.4.1
 
Raf Szczypiorski
Ranch Hand
Posts: 383
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you.
 
Ranch Hand
Posts: 10198
3
Mac PPC Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ralf: Here the question was as to which method out of the two marked as @PostConstruct will be invoked?
 
Ranch Hand
Posts: 757
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Jothi Shankar Kumar wrote:Ralf: Here the question was as to which method out of the two marked as @PostConstruct will be invoked?



As I know, it is unpredictable.
 
Ralph Jaus
Ranch Hand
Posts: 342
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Ralf: Here the question was as to which method out of the two marked as @PostConstruct will be invoked?


Having more than one post-construct method (the same holds for any other lifecycle event) in one class is not compliant with the ejb 3.0 spec. So the behavoir of the system is undefinied. But if there are several post-construct methods distributed over serveral classes then the order is definied by the spec (see my post above).

 
See where your hand is? Not there. It's next to this tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic