• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Bear Bibeault
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Jj Roberts
  • Tim Holloway
  • Piet Souris
Bartenders:
  • Himai Minh
  • Carey Brown
  • salvin francis

URLyBird 1.3.2: Where do you call the Data class's lock() and unlock() method?

 
Ranch Hand
Posts: 126
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
After I read some topic according to lock mechanism, I find that most rachers use the lock() and unlock() like this:

or

...
lock(recNo);
update(recNo,data);
unlock(recNo);
...



And it looks like these codes are all in the client side.

Did anyone use the lock() and unlock() method like this:

 
author and jackaroo
Posts: 12199
280
Mac IntelliJ IDE Firefox Browser Oracle C++ Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Sun,

This may not be a good idea. I will leave the argument over Should lock methods be callable by the client alone for now, as that is separate from the potential problem you might cause yourself.

The problem I see is that calling the lock method from within the update method leaves the potential for somebody to overwrite another person's booking (or even book a deleted record). Consider the following:
  • Client A checks that record 1 has not been booked
  • Client B checks that record 1 has not been booked
  • Client A books record 1 (calls the update() method)
  • Client B books record 1 (calls the update() method)
  • Now client A thinks that they have successfully booked record 1, but the database shows that client B owns the record

    This problem can be overcome by using the lock() method to logically block one client from even confirming availability the record until the other client has finished.

    Regards, Andrew
     
    Opportunity is missed by most people because it is dressed in overalls and looks like work - Edison. Tiny ad:
    the value of filler advertising in 2020
    https://coderanch.com/t/730886/filler-advertising
    reply
      Bookmark Topic Watch Topic
    • New Topic