Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

record locking and file access locking

 
Yan Zhou
Ranch Hand
Posts: 137
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Regardless of the assignment, it seems to me that there are two levels of synchronization required, the first one is at the business level, so that no two clients can modify the same record at the same time. The second one is at file level, so that no two threads can modify the file at the same time, even if they are updating different records.

The lock on file level can simply be implemented by synchronized methods, but if that is the case, what value of the first level record locking, since update to file can only happen one at a time?

Am I correct on this?
Thanks.
Yan
 
peter wooster
Ranch Hand
Posts: 1033
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Yan Zhou:
Hi,

Regardless of the assignment, it seems to me that there are two levels of synchronization required, the first one is at the business level, so that no two clients can modify the same record at the same time. The second one is at file level, so that no two threads can modify the file at the same time, even if they are updating different records.

The lock on file level can simply be implemented by synchronized methods, but if that is the case, what value of the first level record locking, since update to file can only happen one at a time?

Am I correct on this?
Thanks.
Yan


Business transactions like booking rely on sequnce such as
- get a row from the table
- read a record to confirm it matches the row
- modify the record
- write the record

If this relied only on the file level locking a second user could modify the record between the read and the write, unless you did the whole thing with the file locked. If your business logic is on a distributed client system, this would be a very poor design. Even withthe business logic on the server, it interlocks all reads and writes while a user does a book. Thus the sequence
- lock
- read
- modify
- write
- unlock

Is introduced to allow only a single record to be held while the booking is done.

In an Oracle system this would be accomplished with
- read for update
- modify
- update
- commit
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic