The problem with synchronizing a shared home is reduced concurrency, and
hence reduced performance. Synchronizing on home effectively reduces EJB
to a single-threaded service for all create and finder queries on the
same table, disabling concurrency opportunities on the container. EJB
synchronization should be the purview of the EJB container, which holds
all the cards in deciding when it makes sense.
Although I don't doubt the experience, I remain unclear about the
mechanism. Where is the resource contention? Given a scenario:
Thread A obtains MyHome.
MyHome invokes operation.
Thread A suspends execution.
Thread B starts.
Thread B obtains MyHome.
MyHome invokes operation.
Thread B suspends execution.
Thread A resumes.
MyHome returns operation result.
Application crashes.
what caused the application to crash? AFAIK the home stub doesn't have
volatile state. The invocation parameters and result are on the
thread-specific stack activation record, not the dynamic heap. What
could Thread B change that affects Thread A?
Fred Loney
Spirited Software, Inc.
www.spiritedsw.com
----- Original Message -----
From: "Ian McCallion" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Thursday, October 25, 2001 8:27 AM
Subject: Re: EJBHome and thread safety
> Tim Fox wrote:
> >
> > I'm not doubting you, but can you tell us how you came to the
conclusion
> > that the EJBHome stub is not thread-safe?
> >
> > It's just that, if true, I have lots of code to rewrite (the
Home-cache
> > pattern is very popular) :(
>
> Tim, As I already stated, practical experience.
>
> What actually happened was that my app could be crashed reliably by
> simultaneously initiating two requests from different browsers, and
when I
> synchronized use of EJBHome it became reliable again.
>
> Incidentally it's also necessary to synchronize around calls to
EJBObjects
> because the servlet engine will happily dispatch two requests on
separate
> threads as a result of extra clicks in a single browser window.
>
> BTW, there's no big redesign needed - just put
>
> synchronized(myHome){
> ...
> }
>
> around each use of myHome.
>
> ========================================
> 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".
>
===========================================================================
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".