aspose file tools*
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes lock-modify- unlock Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "lock-modify- unlock" Watch "lock-modify- unlock" New topic
Author

lock-modify- unlock

ravi janap
Ranch Hand

Joined: Nov 04, 2000
Posts: 389
Hi
Is this mode lock-modify-unlock of modifying data must only be performed in network mode ?
I have designed the architecture in such a way that All the calls to Data object are made through DataAdpater object. The Client directly calls the methods in DataAdapter object in local mode whereas in network model Client talks to DataImpl class ( the server object ) which in turn talks to DataAdpater.
Now the DataAdapter class has modify implemented in the following fashion:
method modify
{
data.lock();
data.modify();
data.unlock();
}
Thanks
Ravi


SCJP, SCJD, SCWCD, SCBCD, SCEA
Chandru Ganesan
Ranch Hand

Joined: Feb 08, 2003
Posts: 37
I dont think it is a good idea to implement locking in local mode. I choose to extend the Data class to implement lock/unlock methods. The Data class has dummy lock(), unlock() methods. This will ensure that without changing the Adpater class you can implement locking under Network mode and no locking under local mode
my 2 cents
Chandru
Peter den Haan
author
Ranch Hand

Joined: Apr 20, 2000
Posts: 3252
Originally posted by janapareddy ravindra:
Is this mode lock-modify-unlock of modifying data must only be performed in network mode ?
Two things.
First, the answer depends on what exactly you mean by that question. The client must always go through the motions of locking and unlocking. Whether the lock() and unlock() methods contain any meaningful implementation code is another matter; in Data, they might not.
Second, lock-modify-unlock is not enough and basically won't achieve anything. You need a lock-read-modify-unlock cycle.
- Peter
Chandru Ganesan
Ranch Hand

Joined: Feb 08, 2003
Posts: 37
Peter,
quote:
"Second, lock-modify-unlock is not enough and basically won't achieve anything. You need a lock-read-modify-unlock cycle."
By lock-read-modify-unlock do you mean the record will be locked until client finishes with the update.
If so, I see something wrong with this. In this case how is it possible for 2 clients to concurrently modify the same record as identified in the submission doc.
Chandru
Peter den Haan
author
Ranch Hand

Joined: Apr 20, 2000
Posts: 3252
Originally posted by Chandru Ganesan:
By lock-read-modify-unlock do you mean the record will be locked until client finishes with the update.
Yes -- but keep in mind that the this whole cycle will typically take a fraction of a second.
If so, I see something wrong with this. In this case how is it possible for 2 clients to concurrently modify the same record as identified in the submission doc.
You're misinterpreting the requirements. Concurrent updates are handled precisely by preventing some things from happening truly concurrently using the lock methods. If you don't, then race conditions between clients can easily lead to double-booking of seats.
- Peter
ravi janap
Ranch Hand

Joined: Nov 04, 2000
Posts: 389
Hi Peter
What I mean is that is lock and unlock needed if the application is being run in the local mode.
I have modified my implementation of modify method
to incorporate lock-read-modify-unlock.
modify(DataInfo newData)
{
int record = newData.getRecordNumber();
data.lock(record);
DataInfo modifyData = data.getRecord(record);
data.modify(modifyData);
data.unlock(record);
}
I hope now this implementation is correct.
Thanks
Ravi
ravi janap
Ranch Hand

Joined: Nov 04, 2000
Posts: 389
Hi Chandru
I thought about your suggestion. That would mean that, say if I have another class say NetworkData which extends Data class. I can implement dummy lock and unlock in Data class and provide the needed implementation in NetworkData class. Now the DataAdapter object would call the methods on NetworkData object in remote mode and call the methods on Data object in local mode. Is this approach okay.
I also hope that I don't need to worry about read-modify in the local mode since there were typically be one client operating in the local mode. Is that correct ?
Thanks
Ravi
Chandru Ganesan
Ranch Hand

Joined: Feb 08, 2003
Posts: 37
Hi Ravi,
Sorry for the late response, was out of town. That's exactly what I did. I used lock()/update()/unlock() and lock()/read()/unlock() convention in the adapter class. In case of local mode the dummy lock()/unlock() methods in the Data class w'd enusre no locking is performed and for remote mode the NetworkData class overrides the lock()/unlock()in Data. This is a plain simple implementation.
good luck
Chandru
ravi janap
Ranch Hand

Joined: Nov 04, 2000
Posts: 389
Hi Chandru
I have uploaded the assignment yesterday and this is the same approach followed by me based on your suggestion. I am planning to take the exam immedietly now.
Thanks
Ravi
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: lock-modify- unlock