Hi All, I am not sure that I understand the record locking mechanism requested in the Fly By Night assignment. The methods given for accessing the database (just a binary file with a private handler in the Data class) in the Data class are all synchronized. Eg. Modify, find, getRecord. So what is the point of doing record locking? Irrespective of whether I lock record number 7 or 8, when I do a modify, (since modify is synchronized on the object) the whole database is locked. Record locking makes sense only if concurrent connections can modify different records at the same time. But since we use synchronize in modify method any connection trying to do a modification has to block if another connection is doing a modification even though the modification might be on different records. So should we drop the synchronized keyword in the modify method signature or Am I way off in understanding the requirements. Response would be greatly appreciated Thanks -Sri
Sri, Locking is needed because of the time lag between the a call to, say, modify() at the client and the actual entry of the method Data.modify(). Synchronization is needed in Data because multiple threads may be running in the server program. Jerry
Joined: Dec 11, 2000
Jerry, Thanks for the response. I would like more clarification in understanding the requirement. I understand the need for locking and synchronization, but what I do not understand how Record level locking can be acheived with the synchronization on methods ( modify, getRecord etc) that lock the whole database To illustrate A thread executing a synchronized method acquires lock for the object, in this case the Data Object. No other thread can acquire the lock for this Data object if another thread has already acquired it The implication here is that if one client tries to update a given record it essentially prevents *any* client from updating *any* record. Why? because the Data object is what is being synchronized on. So how do we do a record level locking in this scenario?
Thanks in Advance -Sri
Joined: Sep 19, 2000
Sri, A seat-booking action extends over more than one method call. Suppose client A reads a record (with getRecord()) and finds 1 seat available, then client B reserves the seat (with modify()), then A reserves it (also with modify()). Even though each single method call was protected in a critical section, the sequence wasn't. The only way around this problem is for A to be able to lock the record, read the number of seats and verify one is still available, reserve it, then unlock the record. You lock by keeping some kind of per-record data structure that marks whether the record is locked. For a discussion of some of the issues this raises, see this thread and this one. Jerry