Thanks Ole. Always something interesting to learn out there. 

> -----Original Message-----
> From: Ole Husgaard [mailto:[EMAIL PROTECTED]]
> Sent: Wednesday, January 31, 2001 8:00 AM
> To: jBoss
> Subject: Re: [jBoss-User] LOCKING-WAITING (TRANSACTION)
> 
> 
> Hi,
> 
> "Nortje, Andrew" wrote:
> > OK I got it figured. I got the dead lock situation that Ole 
> sketched. BTW if
> > anyone is dealing with accounts and account balances NEVER 
> update the
> > account balance when you are inserting line items, you are 
> sure to get
> > deadlock. Only update the balance once in a while, or when 
> necessary (e.g.
> > when the customer wants to withdraw funds), from 
> information in the account
> > line items.
> 
> One way to get around such deadlocks is by
> ordering access to you beans within
> transactions.
> 
> For example, if you have entity beans Account
> and AccountLine, with instances account and
> accountLine, you can get around the deadlock
> if you always access account first when you need
> to access both instances.
> 
> The following two threads might deadlock:
> 1: accountLine.getAmount(...);
>    account.updateBalance(...);
> 2: account.getBalance(...);
>    accountLine.getAmount(...);
> 
> But if Account is always accessed first, no
> deadlock:
> 1: account.getBalance(...);
>    accountLine.getAmount(...);
>    account.updateBalance(...);
> 2: account.getBalance(...);
>    accountLine.getAmount(...);
> 
> The extra call in thread 1 above ensures that
> the account is locked first. And if the account
> is always locked first when you need to lock
> both account and accountLine, the deadlock
> scenario I described cannot happen (at least
> not between these two beans).
> 
> 
> Best Regards,
> 
> Ole Husgaard.
> 
> 
> --
> --------------------------------------------------------------
> To subscribe:        [EMAIL PROTECTED]
> To unsubscribe:      [EMAIL PROTECTED]
> List Help?:          [EMAIL PROTECTED]
> 


--
--------------------------------------------------------------
To subscribe:        [EMAIL PROTECTED]
To unsubscribe:      [EMAIL PROTECTED]
List Help?:          [EMAIL PROTECTED]

Reply via email to