• 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
  • Tim Cooke
  • paul wheaton
  • Paul Clapham
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Roland Mueller
  • Piet Souris
Bartenders:

Question on Singleton Session Bean Instantiation

 
Ranch Hand
Posts: 634
Eclipse IDE Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Source:OCP JavaEE 6 EJB Developer Study Notes by Ivan A Krizsan,Version: April 8, 2012



Hi All,

Below is the Code for Singleton Session Bean and Client Servlet that accesses the Bean.

Singleton Session Bean


Client Servlet


Below is the messages logged server.log:




Request Issued:

http://localhost:8080/BusinessMethodInterceptors/
http://localhost:8080/BusinessMethodInterceptors/test.do

Here,BusinessMethodInterceptors is the name of Web Project.

As per my understanding,Singletion Session Bean is instantiated once per application per class.
However, in the server.log I see that it is Instantiated(Created) twice in application (See message "INFO: *** SingletonSessionBeanA - Created" is displayed twice)
Please advise if my understanding is incorrect.
 
Creator of Enthuware JWS+ V6
Posts: 3412
320
Android Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Mohit,

This is what I also noticed when I was preparing for the exam: the constructor of a Singleton is called twice (!). This is an implementation specific thing not mandated (or explained) by the specifications. The PostConstruct method is only called once luckily...

Regards,
Frits
 
Mohit G Gupta
Ranch Hand
Posts: 634
Eclipse IDE Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks again Frits
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic