Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

About the lock and unlock

 
Ying Ren
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I feel some complicated in Locking and unlocking. I implement the methods in my data. And I use a static hashset for locks. Why should we use the lockmanager, what the main point of that?
Another question, when booking, I just use the modify method,it works well. Why did some posts say we should use read and write?
Please help me!!!
YING REN
 
Robin Underwood
Ranch Hand
Posts: 117
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Modify() does seem to have a bug that it assumes that the first field on each record (flight number) is unique. But there didn't seem to be a better alternative. The writeRecord method is private. To avoid changing the Data class, I am going to use modify() but also document its bug.
 
Sai Prasad
Ranch Hand
Posts: 560
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Data class is responsible to provide methods to manipulate the flight data. In order to avoid data corruption due to multiple threads accessing the RMI server, LockManager is used. Since this is purely a server functionality, it shouldn't be in the Data class.
In order to get the DataInfo instance, using the record number from the table model, you do a lock -> read -> modify -> unlock. You want to do the read to make sure someone else didn't modify the record while the current user was on a break after the flight search!
 
Holmes Wong
Ranch Hand
Posts: 163
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Robin Underwood:
Modify() does seem to have a bug that it assumes that the first field on each record (flight number) is unique. But there didn't seem to be a better alternative. The writeRecord method is private. To avoid changing the Data class, I am going to use modify() but also document its bug.

Yes, this assumption is kind of fishy. But since
the modification is based on the record number also, this function can still work well.
Sai:
I heard lots of people talk about lock->read->modify->unlock. What is this "read"? You mean
the search action (when user presses "search button")? Since flight search event will be handled in a different event handler than book event. You mentioned LockManager should be on server-side, where to use lock/unlock? Define FlightSearch and Book methods on the server-side and use lock/unlock there? I am kind of confused here. Thanks.
 
Sai Prasad
Ranch Hand
Posts: 560
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

I heard lots of people talk about lock->read->modify->unlock. What is this "read"? You mean
the search action (when user presses "search button")? Since flight search event will be handled in a different event handler than book event.
I mean the sequence during booking of flight. After the user selects a flight to book seats, you read the flight number, do a find by passsing the flight number, lock the record, modify the seats, update the database and unlock the record.

You mentioned LockManager should be on server-side, where to use lock/unlock? Define FlightSearch and Book methods on the server-side and use lock/unlock there?
You can implement the access for locking and the blocking of threads in the LockManager. You define the FlightSearch and Book methods in the client side Facade or Controller.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic