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

locking & unlocking

 
poornima sudharshan
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have 2 queries -
1. On the screen which displays the JTable, the user selects a record,but since the assignment does not say that we have to display live records,I have to get the available seats from the database.If the particular record is locked,I wil wait,since my intention is to get the latest information.
Then after getting the current available seats, I will lock the record.
Is this correct?
2.My second question is how do I implement timeout.Can I use a hashtable wherein I put the particular record to be locked & the time stamp- the time this record was put.
when the time elapsed is greater than the certain allocated time,the record has to be unlocked or removed from the hashtable.
Is this correct?
Please reply.
poornima.
 
Jayakumar Duraisamy
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Poornima,
1. Locking the record.
You are almost right. Don't worry about the live record which is a client side requirement. You should try to get the lock before getting the available seats. For example, the client book seats request should follow the below scenario.
1. lock(rec) - it checks whether the record lock is available, if so it obtains the lock and go to the next step. else it waits.
2. read(rec) - to get the latest information
3. modify(rec) - by reducing the no of seats from the request
4. unlock(rec) - and notify the clients who are waiting in step 1.
2. Lock Time out
Here again, u are right. But few more points..
1. You can use Synchronized HashMap instead of Hashtable
Regards
Jay
 
Ruslan Ivanov
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi , i have a question. Let's say i let the client call lock/ unlock. How would i know that the lock was successful. So that i can show him a dialog later on where he can choose number of seats too book.
thanks
 
Rick Fortier
Ranch Hand
Posts: 147
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Ruslan Ivanov:
Hi , i have a question. Let's say i let the client call lock/ unlock. How would i know that the lock was successful. So that i can show him a dialog later on where he can choose number of seats too book.
thanks

No, I would not do it that way.
1. Display the records as they are to the user.
2. Let them select a flight and number of seats.
3. Lock the record
4. Read the record
5. See if enough seats are still available, if not display error
6. Modify the record
7. in a finally, unlock the record
8. Display to the user some nice message saying Thank You,
your seats for flight XXX have been booked for XX number of seats.
 
Ruslan Ivanov
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The thing is i want to know if the lock was successfull. Lets say i want to do what you just said . Lock the record then readRecord before i can do reading i must make sure that i locked it right ? How would i know that lock was placed there is no where for me to find out. Lock has no return type.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic