Win a copy of Java Mock Exams (software) this week in the Programmer Certification (OCPJP) forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

no need to lock! ??

J Hartley
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, from my FBN instructions....
"Note that the locking required is effectively a "write" lock only. If updates occur to a record that is being displayed on another client, then no change occurs at the other client. However, if two clients attempt to perform the sequence lock, read, modify, write, unlock concurrently, then both modification attempts will be handled correctly. The aim is to ensure that if two customers attempt to book a seat on the same flight concurrently, then the number of available seats is definitely reduced by two, unless there was only one seat, in which case, one customer will be advised at booking time that no more seats are available."
i cant see the need to implement any locking. the modify method is synchronised, so for example
client A sees that there is 1 seat left
client B sees that there is 1 seat left
client A calls modify
client B calls modify
Because client a called first it gets the lock from Data instance. the seats are reduced by 1. client A is happy
Client B then gets the lock and enters the modify method, if there the seats = 0 then report failure, in this particular case it does.
simple eh? am i missing something?
Cheers Joe
What are you doing? You are supposed to be reading this tiny ad!
the new thread boost feature brings a LOT of attention to your favorite threads
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!