8 misc questions about EJB
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Stan_UA1OUT
Posted On:   Wednesday, November 21, 2001 07:22 AM

Hi everyone, Thanks to all of you who ask questions and especially to those who find time to answer them. You have helped me very much already. I've got a few generic questions about EJBeans. I marked them in the text with Qs. Answers to any of them would be appreciated. InitialContext. The close method of the interface is supposed to be called to free resources. It seems to be a common practice never to use it (from what I see in examples and other’s code). Usually I “new” InitialContext in ejbCreate, store a reference in a class member of the bean and free it in ejbRemove. Q1: Is my approach ok? Q2: Should I use close at all? Stateless beans. Q3: Do I need to always “   More>>

Hi everyone,



Thanks to all of you who ask questions and especially to those who find time to answer them. You have helped me very much already.



I've got a few generic questions about EJBeans. I marked them in the text with Qs. Answers to any of them would be appreciated.



InitialContext. The close method of the interface is supposed to be called to free resources. It seems to be a common practice never to use it (from what I see in examples and other’s code). Usually I “new” InitialContext in ejbCreate, store a reference in a class member of the bean and free it in ejbRemove. Q1: Is my approach ok? Q2: Should I use close at all?



Stateless beans. Q3: Do I need to always “remove” them after use (both on the client and in other beans)? Q4: Would Weblogic take care of the situation when remove is not called for a bean (or a lot of beans)?



Missed ejbRemoves. EJB 2.0 specs describes cases when ejbRemote does not get called. In ejbRemove I would normally free resource I allocated in ejbCreate (context, references to other beans, etc). Q5: Is it ok to ignore missed removes?



Caching stateless beans. The following is what I normally do: in ejbCreate lookup JNDI to obtain homes of all beans I am going to use in all methods of the bean. In methods I get hold of remotes. When getting references to stateless beans, I guess, it would make sense to cache remote interfaces of the stateless beans in ejbCreate as well (Q6). There might be a situation when the server removes the bean on timeout. How would I handle it (Q7)? Q8: Is instantiating an EJBean using serialized handle any faster then going through JNDI lookup for home and ejbCreate for remote interface?



That’s it.



Thanks again.



Stan

   <<Less

Re: 8 misc questions about EJB

Posted By:   Bozidar_Dangubic  
Posted On:   Wednesday, November 21, 2001 08:56 AM


  • you do not have to bother closing InitialContext. (this is for Q1 and Q2)
  • you do not have to "remove" stateless session beans after you used them, but you can. container pools stateless session beans so it is likely that even in two subsequent invocations to the stateless session bean (using the same reference) different stateless session bean instance is actually doing the work for you. so you can "remove" if you want, but for any decent app server it is not necessary.
  • Q4: it should.
  • Q5: I am guessing you are still talking about stateless session beans. if you are, as I said above, good containers should call remove for you. however, if you are allocating a lot of resource it would not be such a bad idea to call remove yourself from the client code or in the bean after each method invocation.
  • Q6/Q7: use EJBHandle, i.e. cache the handle, not the remote reference. from the handle, you can get back the reference to the bean if it was removed by the container.
  • Q8: yes
About | Sitemap | Contact