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 ??
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
Any intelligent fool can make things bigger, more complex, and more violent. It takes a touch of genius - and a lot of courage - to move in the opposite direction. - Ernst F. Schumacher
Joined: Aug 07, 2002
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 ?
Joined: Jan 30, 2002
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