You are viewing a plain text version of this content. The canonical link for it is here.
Posted to ojb-user@db.apache.org by Fiona Magner <f_...@hotmail.com> on 2004/07/06 18:00:23 UTC

Concurrency question

Hi there:

I am just beginning to use OJB in a Web application. The particular web application (when it goes live with OJB) will be required for high availability. I have a question about a concurrency issue that I have come across. Consider the following example. Two users, a and b are accessing the customers table and updating the customers balance. 

                                                                                                                                          
// 1.User A gets customer record 123 (bean) from database. 
Customer has balance of 0             
       
        // 2. User B gets customer record 123 (accountbalance = 0)

// 3.User A make changes to bean object using retrieved values
    eg. c.setAccountbalance(c.getAccountbalance() + 20.00) 
    (customer will now have balance of 20)

        // 4. User B makes changes to account balance (balance now 20)
                
// 5. User A sends updates to database (stored balance is now 20)
    
        // 6. User B sends updates to database (stored balance is now 20 *** should be 40)

Note that steps 1, 3 and 5 actually all happen within the one script (as do 2, 4 and 6) but I have just outlined them as separate steps above for clarity. As you can see it is possible for two concurrent users to cause inconsistency in the data. Is it necessary to have a markDirty() step in the script before applying the changes? Also can you tell me if this markDirty() will put a lock on the table until the changes are committed? Like I say this will be a high throughput site and therefore I would like to avoid any lengthy locks on the tables while updates are being carried out. I hope my email is clear, if you require any more info please let me know.

Thanks!
Fiona


Re: Concurrency question

Posted by Jin Bal <ji...@hotmail.com>.
I think using the optimistic offline lock approach will be sufficient for
your needs.

There is doc on the OJB site. but basically any update increments a version
number which ojb checks and compares to the version it's about to save and
throws an exception which indicates that there is a concurreny conflict.

You can detect this and tell the user that someone else is editing the same
thing and let them decide how to proceed.

HTH

Jin

----- Original Message -----
From: "Fiona Magner" <f_...@hotmail.com>
To: <oj...@db.apache.org>
Sent: Tuesday, July 06, 2004 5:00 PM
Subject: Concurrency question


Hi there:

I am just beginning to use OJB in a Web application. The particular web
application (when it goes live with OJB) will be required for high
availability. I have a question about a concurrency issue that I have come
across. Consider the following example. Two users, a and b are accessing the
customers table and updating the customers balance.


// 1.User A gets customer record 123 (bean) from database.
Customer has balance of 0

        // 2. User B gets customer record 123 (accountbalance = 0)

// 3.User A make changes to bean object using retrieved values
    eg. c.setAccountbalance(c.getAccountbalance() + 20.00)
    (customer will now have balance of 20)

        // 4. User B makes changes to account balance (balance now 20)

// 5. User A sends updates to database (stored balance is now 20)

        // 6. User B sends updates to database (stored balance is now 20 ***
should be 40)

Note that steps 1, 3 and 5 actually all happen within the one script (as do
2, 4 and 6) but I have just outlined them as separate steps above for
clarity. As you can see it is possible for two concurrent users to cause
inconsistency in the data. Is it necessary to have a markDirty() step in the
script before applying the changes? Also can you tell me if this markDirty()
will put a lock on the table until the changes are committed? Like I say
this will be a high throughput site and therefore I would like to avoid any
lengthy locks on the tables while updates are being carried out. I hope my
email is clear, if you require any more info please let me know.

Thanks!
Fiona


---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-user-help@db.apache.org


Re: Concurrency question

Posted by "Michael A. Hovan III" <mh...@hovan.org>.
You may want to use optimistic locking.  You will have to write code to 
handle the lock failure situations when storing and it requires an 
additional column on your tables.  But, it does not hold locks in the 
tables and is a more general mechanism for handling concurrency.  We 
are using it to good effect in a moderately loaded distributed 
simulation application to moderate our database concurrency.

Make sure that you are using OJB 1.0 or later if you decide to use 
Optimistic Locking with a Timestamp column an Oracle Database and Java 
1.4.x.  There is an ugly interaction between the new Java Timestamp and 
the Oracle Driver which I believe was worked around just before the OJB 
1.0 release.


Mike


On Jul 6, 2004, at 12:00, Fiona Magner wrote:

> Hi there:
>
> I am just beginning to use OJB in a Web application. The particular 
> web application (when it goes live with OJB) will be required for high 
> availability. I have a question about a concurrency issue that I have 
> come across. Consider the following example. Two users, a and b are 
> accessing the customers table and updating the customers balance.
>
>
> // 1.User A gets customer record 123 (bean) from database.
> Customer has balance of 0
>
>         // 2. User B gets customer record 123 (accountbalance = 0)
>
> // 3.User A make changes to bean object using retrieved values
>     eg. c.setAccountbalance(c.getAccountbalance() + 20.00)
>     (customer will now have balance of 20)
>
>         // 4. User B makes changes to account balance (balance now 20)
>
> // 5. User A sends updates to database (stored balance is now 20)
>
>         // 6. User B sends updates to database (stored balance is now 
> 20 *** should be 40)
>
> Note that steps 1, 3 and 5 actually all happen within the one script 
> (as do 2, 4 and 6) but I have just outlined them as separate steps 
> above for clarity. As you can see it is possible for two concurrent 
> users to cause inconsistency in the data. Is it necessary to have a 
> markDirty() step in the script before applying the changes? Also can 
> you tell me if this markDirty() will put a lock on the table until the 
> changes are committed? Like I say this will be a high throughput site 
> and therefore I would like to avoid any lengthy locks on the tables 
> while updates are being carried out. I hope my email is clear, if you 
> require any more info please let me know.
>
> Thanks!
> Fiona
>


---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-user-help@db.apache.org