EJB programming & troubleshooting: Removing a stateful session bean from client code
I required your help in developing my J2ee based applicatin in which I am
- Posted by: Noman Ahmed
- Posted on: February 23 2005 03:25 EST
using 3-tier architecture. My page flow is as following,
(in which he gets id and password and create stateful session bean and pass
these parameter to SFSB business method that method calls create local BMP
entity bean and pass those id and password to entity bean business method
and then get result and return back to jsp page in that page I set two session
variable one is based on database result which we get on behalf of id and password
and other is my remote object of SFSB, then i go to next page Home.jsp)
(in this page I get session objects and display some result and in this page I have a link of logout.jsp
page when user click that link it goes to logout.jsp page)
(the code of that logout.jsp page is)
out.println("You have sucessfully log out");
My question in this regard is that whether I should remove SFSB here by myself it is good technique or container
should do this to me any thing about this code any suggestion or code u refer to me will be very helpful for me
From Noman Ahmed
If you don't remove the bean the EJB container will passivate the bean when it needs the memory.
Passivation is a very expensive operation, particularly when the SFSB contains a number of Java objects.
Removing the SFSB frees memory by moving the bean into "Does Not Exist State". When the bean times out,
the container might call ejbRemove(), but it does not have to.
Recall that SFSBs are not pooled, as are stateless session beans. There is one SFSB for every client reference.
I suggest you reassess your design and see whether you really need to use SFSBs (and whether you need to use BMP
rather than CMP entity beans).
There are many great design and coding resources, including free books, right here on TheServerSide, that will give you guidance.
In my opinion, you need to refactor the architecure of your application. EJB code in JSP pages is not elegant, I would use the mvc pattern to divorce the layers.
the clasic architecture would be
depanding on your requirement, you may for example do :
1) jsp --> controller servlet (ie struts) -->EJB
2) jsp --> controller servlet (ie struts) -->DAO
I hope understood your question.