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
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.
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 ]
Joined: Sep 10, 2002
"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?
Joined: Sep 05, 2003
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.