File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes a Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "a "write" lock???" Watch "a "write" lock???" New topic
Author

a "write" lock???

shao zhimin
Greenhorn

Joined: Aug 07, 2002
Posts: 16
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 ??
Michael Morris
Ranch Hand

Joined: Jan 30, 2002
Posts: 3451
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
shao zhimin
Greenhorn

Joined: Aug 07, 2002
Posts: 16
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

Joined: Jan 30, 2002
Posts: 3451
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: a "write" lock???