• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

a "write" lock???

 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In SCJD Documents written:"Note that the locking required is effetively a "write" lock only." and "...the sequence lock, read, modify, write,unlock..."
What's meaning? Why not the sequence is "read, modify, lock, write, unlock"??? Do you implement this ??
 
Ranch Hand
Posts: 3451
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi shao,
First of all you will need to change your display name to a first and last name if you want to continue getting the best Java help anywhere on the www.
A write lock simply means that while one client is in the process of modifying a particular record, any other client may read that record without constraint.


Why not the sequence is "read, modify, lock, write, unlock"


Well, what happens if two (or fifteen) clients perform this sequence at the same time? You have a race condition which will almost certainly result in the corruption of that record. Say that there were only one seat available and three clients read the record before any modify. All three clients would believe that they had sucessfully booked the flight after modification. You would have three very angry customers when they showed up at the airport and found out there was only one seat available.
Hope this helps,
Michael Morris
 
shao zhimin
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If the sequence is "lock, read, modify, write, unlock", then one client is modifying the record,
however the other can read the record. Is right?
how to implements the lock ?
 
Michael Morris
Ranch Hand
Posts: 3451
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Shao,


If the sequence is "lock, read, modify, write, unlock", then one client is modifying the record,
however the other can read the record. Is right?


That's it, even though the read may (and probably will) return stale data to all reading clients while the lock is in place.


how to implements the lock ?


Well that's a big part of the assignment, isn't it? Most have implemented a LockManager class that keeps up with locked records and the clients that own those locks. Whatever data structure you use to store the currently locked records has to be thread-safe so that two different clients are not allowed to lock the same record concurrently; one will have to wait for the other to unlock the record before receiving the lock. That's why the instructions say that the lock method should "block" if the lock is currently owned by a different client.
Hope this helps,
Michael Morris
 
No prison can hold Chairface Chippendale. And on a totally different topic ... my stuff:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic