This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes EJB Certification (SCBCD/OCPJBCD) and the fly likes Question on Singleton Session Bean Instantiation Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » EJB Certification (SCBCD/OCPJBCD)
Bookmark "Question on Singleton Session Bean Instantiation" Watch "Question on Singleton Session Bean Instantiation" New topic
Author

Question on Singleton Session Bean Instantiation

Mohit G Gupta
Ranch Hand

Joined: May 18, 2010
Posts: 634


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.


OCPJP 6.0 93%
OCPJWCD 5.0 98%
Frits Walraven
Creator of Enthuware JWS+ V6
Bartender

Joined: Apr 07, 2010
Posts: 1624
    
  23

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

Joined: May 18, 2010
Posts: 634

Thanks again Frits
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Question on Singleton Session Bean Instantiation
 
Similar Threads
cant load the admin console in glassfish v3
Help With Rest EJB
a blank glassFish admin console @ netbeans 6.8
GlassFish v3 and localhost in Windows7
Call EJB from Application Client