Ted Neward wrote: > > They *could* become a shared resource, however, if the client runs multiple > threads against the same session bean reference, which is quite common in > servlet applications.... > > The EJB Spec guarantees that only one method call at a time will be allowed > on any Bean, IIRC, so other callers will be blocked on any bean method until > the first method completes and returns.
No. The spec guarantees only one method call at a time will be allowed, but containers don't do the synchronisation. So if you don't synchronize access to EJBs (EJBHomes and EJBObjects) from servlets you'll get exceptions raised when race conditions occur. This is not necessarily simply a matter of putting synchronize() blocks around the calls to the EJB for two reasons: 1. For very high thruput applications synchronizing calls to EJBHome may cause a bottleneck, so get a new copy of the EJBHome object whenever needed. 2. When viewing a page containing buttons that invoke your servlet a web user can click the buttons multiple times and if this happens your servlet will get multiple requests from the user that may be processed in parallel on different threads. This potentially nasty situation that can cause several problems - not just the problem of parallel invocations of EJBs, so cast your synchronization net wide, and carefully choose the object to synchronize on - the EJBObject may not be appropriate since it may not always exist. Ian ======================================== Ian McCallion Alexis Systems Limited Romsey, UK Tel: +44 1794 514883 Fax: +44 1794 501692 ======================================== =========================================================================== To unsubscribe, send email to [EMAIL PROTECTED] and include in the body of the message "signoff EJB-INTEREST". For general help, send email to [EMAIL PROTECTED] and include in the body of the message "help".
