• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

About the lock and unlock

 
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 117
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 560
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!
 
Ranch Hand
Posts: 163
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
I don't even know how to spell CIA. But this tiny ad does:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic