• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Locking peseduo

 
GD Deepz
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 11945
212
C++ Firefox Browser IntelliJ IDE Java Mac Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi GD,

Your psuedo-code shows you
  • lock database
  • lock record
  • ...
  • unlock database
  • unlock 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
     
    • Post Reply
    • Bookmark Topic Watch Topic
    • New Topic