From: Brian M. <bri...@au...> - 2003-03-07 16:45:02
|
thanks very much StatsK, very clear. I think the only thing I'm still unsure of is the lifecycle = of stateless session beans. If they can become bad at any stage, is it a good idea to cache it = anyway do you reckon? I really appreciate your help, thanks, Brian ----- Original Message -----=20 From: Stas Krichevsky=20 To: jbo...@li...=20 Sent: Friday, March 07, 2003 3:44 PM Subject: RE: [JBoss-user] Optimise stateless session bean access from = servlets Hi, Re. #1 - Probably you're right, but we're doing it in our product and = till now everything worked. If the reference becomes bad, you can catch = the exception and re-create the reference. Re. #2 - Sure, you can use try/catch blocks in jsp. Re. #3 - The difference between statefull and stateless beans is that = in stateless bean you should pass the "state" to every bean method, i.e. = container may give the same bean instance to different clients. Again, what I suggested was only performance optimization and if you = didn't decide yet on the architecture of your product, it's better to = look at some mvc framework and some design patterns first. ------------------------ StasK -----Original Message----- From: Brian McSweeney [mailto:bri...@au...]=20 Sent: Friday, March 07, 2003 4:37 PM To: jbo...@li... Subject: Re: [JBoss-user] Optimise stateless session bean access from = servlets Thanks StasK, a few points though.=20 1) I've heard you shouldn't hold references for ejbs in the session = objects really.=20 2) when you create the instance, I think you have to wrap it in a try = catch block. I'm not sure if=20 you can do this in scriptlets. But I don't know jsps well. 3) If the session bean is stateless, does it make any sense to hold it = in a HttpSessionObject? ( this leads me to ask the question - if a session bean is stateless, = why is it called "session" at all? would love to know people's opinion about this. Am I being very = stupid? ) Brian ----- Original Message -----=20 From: Stas Krichevsky=20 To: jbo...@li...=20 Sent: Friday, March 07, 2003 1:43 PM Subject: RE: [JBoss-user] Optimise stateless session bean access = from servlets Hi, You could use http session to store instance of the session bean. = Something like following: <% MyStatelessSession theBean =3D (MyStatelessSession) = session.getAttribute("theBean"); If (null =3D=3D theBean) { // create the instance session.setAttribute("theBean", theBean); } // use the bean. %> This way the instance of the bean will be created once per session. Of course you may look at some design patterns too, for example = business delegate pattern (a good example can be found in "Programming = Jakarta Struts" by Chuck Cavaness ). Hope this helps. ------------------------ StasK -----Original Message----- From: Brian McSweeney [mailto:bri...@au...]=20 Sent: Friday, March 07, 2003 2:03 PM To: jbo...@li... Subject: [JBoss-user] Optimise stateless session bean access from = servlets Hi all, My business logic is controlled by stateless session beans. My front-end is probably going to be JSPs which use the session=20 beans. I could create a reference to the session bean each time it's = used, but from my understanding of how it works, when the client=20 calls MyStatelessSessionHome.create( ) we cannot tell if a new = object=20 is actually created on the server.=20 My understanding is that the container can at any time decide which=20 instance of the stateless session bean in the bean pool can be used = for=20 the client's reference. So, my question is - would it not be more = optimal=20 to actually create a reference to each of my stateless session beans = on=20 the main servlet startup (say in init) and let each of my jsps use = the same=20 reference. This would avoid the overhead of bean creation for each = JSP.=20 Thoughts, cheers, Brian |