Win a copy of Java Mock Exams (software) this week in the Programmer Certification (OCPJP) forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

PostConstruct/PreDestroy of a Singleton should be executed in a transaction context

 
Himai Minh
Ranch Hand
Posts: 1398
8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
On p.166 of Ivan's notes,

A transaction context is not available in all methods of EJBs. Examples of methods that execute in an unspecified transaction context include:
1. PostConstruct and PreDestroy methods in EJBs with container managed transactions.
2. PostConstruct and PreDestroy methods of singleton session beans.


For 1), according to the JSR-318, PostConstruct and PreDestroy lifecycle callback methods in stateful/stateless/ message driven bean are executed in unspecified transactional context.
But that does not include singleton.

For 2), according to session 4.8.3 of JSR-318, PostConstruct and PreDestroy methods of a Singleton with CMT are transactional. The transactional attributes are REQUIRED, REQUIRES_NEW or NOT_SUPPORTED.
That means these two methods are executed in
1 ) the client's transactional context;
2) or starts a new transaction while suspending the client's transaction
3) or not in any transactional context at all.

So, I think PostConstruct/PreDestroy methods of a singleton bean are not executed in an unspecified transaction context as described on p.166 of Ivan's notes.
 
Frits Walraven
Creator of Enthuware JWS+ V6
Saloon Keeper
Posts: 2778
174
Android Chrome Eclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So, I think PostConstruct/PreDestroy methods of a singleton bean are not executed in an unspecified transaction context as described on p.166 of Ivan's notes.

You are correct, those methods on a Singleton execute in a transaction context.
 
Happiness is not a goal ... it's a by-product of a life well lived - Eleanor Roosevelt. Tiny ad:
the new thread boost feature: great for the advertiser and smooth for the coderanch user
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!