| Author |
Locking peseduo
|
GD Deepz
Ranch Hand
Joined: Sep 29, 2004
Posts: 55
|
|
Hi guys, as everyone says locking can be a brain twister and it is. What do you all think of the following pseudo code: Book a record: 1.Lock the database 2.Lock the record 3.Read the record from the database to get the most recent data - If record is deleted or already booked inform user Refresh cache memory with current data from database Refresh JTable to display the most recent data Unlock database (Finally statement to ensure its always executed) Unlock record (Finally statement to ensure its always executed) -If record is not deleted or not booked Update database with new booking Refresh cache memory with current data from database Refresh JTable to display the most recent data Unlock database(Finally statement to ensure its always executed Unlock record (in Finally statement to ensure its always executed Delete a Record: 1.Lock the database 2.Lock the record 3.Read the record from the database to get the most recent data If record is deleted inform user Refresh cache memory with current data from database Refresh JTable to display the most recent data Unlock database (Finally statement to ensure its always executed) Unlock record (Finally statement to ensure its always executed) -If record is not deleted Update database ie delete the record or flag it to be deleted Refresh cache memory with current data from database Refresh JTable to display the most recent data Unlock database(Finally statement to ensure its always executed) Unlock record(Finally statement to ensure its always executed) I presume create() will be similiar
|
 |
Andrew Monkhouse
author and jackaroo
Marshal Commander
Joined: Mar 28, 2003
Posts: 10816
|
|
Hi GD, Your psuedo-code shows you lock databaselock record...unlock databaseunlock record] Aren't items 4 & 5 the wrong way around? For that matter, why are you locking the database? All you should need to do from your "booking" method is to lock the individual record. Individual methods within the Data class might have to lock the database while they complete, but these should only be temporary locks. You do not want the entire database locked for the entire book method as this reduces concurrency. Regards, Andrew
|
The Sun Certified Java Developer Exam with J2SE 5: paper version from Amazon, PDF from Apress, Online reference: Books 24x7 Personal blog
|
 |
 |
|
|
subject: Locking peseduo
|
|
|