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 Certification (SCBCD/OCPJBCD) and the fly likes Stateless Sesion Beans and ejbCreate() Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Certification » EJB Certification (SCBCD/OCPJBCD)
Bookmark "Stateless Sesion Beans and ejbCreate()" Watch "Stateless Sesion Beans and ejbCreate()" New topic
Author

Stateless Sesion Beans and ejbCreate()

Murat Balkan
Ranch Hand

Joined: Sep 10, 2002
Posts: 127
Hello,
I am working with Blazix application server to test some ejb callback events. I wrote a session bean and saw that ejbCreate() method is called by the container once, when the first client asks for the business method. I know the container calls this method whenever it decides to add some ejbs to the pool, but does not it have call ejbCreate for every new instance?
In order to test this 2 wrote 2 java client apps that are in a loop creating new instances of the beans and calling the biz methods fine. But the ejbCreate is never called. As I said before it is called once at the beginning. I am confused. Is this the default behaviour, or an application server bug?
Thank you
Murat
Serkan Yazici
Ranch Hand

Joined: Apr 24, 2004
Posts: 33
Merhaba Murat,

It looks like the server is servicing both your clients with the single bean it has created. You can test this by printing the bean instance hashCode inside each business call. If the number of business calls increase for this bean, the server might create more beans, but I say you shouldn't worry about it. After all, that's why the container is there for.

-- Serkan


-- SCJP 1.4 (98%), SCJD (98%), SCWCD (96%), OCA Dev (97% avg.), SCBCD (97%), SCJP 1.5 BETA (90%)<br />-- OCP Dev (maybe), MCDBA (probably) SCEA (eventually)<br />-- Haven't tried Firefox yet? Free, open, secure, fast, tabified, and slick!<br />-- <a href="http://www.mozilla.org/products/firefox/" target="_blank" rel="nofollow">http://www.mozilla.org/products/firefox/</a>
Anselm Paulinus
Ranch Hand

Joined: Sep 05, 2003
Posts: 389
The container doesn't necessarilly have to call ejbCreate in order to add beans to the pull in a SLSB, rather construction and setSessionContext() are enough to add bean to the pool. ejbCreate is called however as an initialization process, and when this occurs is server dependent, though in most cases it is expected that a bean is initialized when created. The point now is depending on whether a single bean services the two clients as this is quite possible with SLSB. The container may or may not have to call ejbCreate a second time as this is purely server dependent. You would get the result you desire, that is wanting ejbCreate to be called twice for the two clients if you use SFSB.
[ May 31, 2004: Message edited by: Anselm Paulinus ]
Murat Balkan
Ranch Hand

Joined: Sep 10, 2002
Posts: 127
"The point now is depending on whether a single bean services the two clients as this is quite possible with SLSB."

Thanks for your responses.

I remember that session beans are not shareable. but here, 1 bean serves two clients at the same time. If so, why the spec says so?

Thanks
Anselm Paulinus
Ranch Hand

Joined: Sep 05, 2003
Posts: 389
One SLSB can not service two clients at the same time. The bean must be done with the servicing of one client before it services the other. The time the bean spents servicing client might be very small compared with the time it takes for the the method calls to get to the bean from the client especially if the bean does not have to access any external resource or any thing of that nature. It might seem to you that you are synchronizing the client calls yet they do not appear so to the bean. You might have to print the values of the hashCodes of the beans as suggested by Serkan Yazici to know if you have more than one bean involved. Let us know what was printed if you do.
 
 
subject: Stateless Sesion Beans and ejbCreate()