• 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
  • Tim Cooke
  • paul wheaton
  • Paul Clapham
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Roland Mueller
  • Piet Souris
Bartenders:

lock while reading data?

 
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Now I only add lock/unlock to those methods which change the record value. But it has a problem:
While read the record from db file, does it need to add a reading lock on record?
If there hasn't a reading lock. while one client thread is reading the record but another client thread changes the record. so the reading client maybe get two different results(before changed or after changed). I think this is not right. So, do I need to add lock to every method which accesses record (both read and write)?
 
Ranch Hand
Posts: 2937
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


So, do I need to add lock to every method which accesses record (both read and write)?


Here is your sequence: lock->read->modify->unlock
Eugene.
 
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I do lock->read->modify->unlock when I try to book a flight. But when I show available flights and flights in combobox (which shows the origin and destination of flights) I do an optimist read (Reading without locking), any comment?
Jawad
 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You should not lock for performing a read to display the flights. What flights are displayed to the user are not necessarily garunteed to be available.
Locking for updating the display would significantly decrease the performance when there are multiple users.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic