• 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

why do i care about locking when i use singleton fileaccess

 
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
if i have a class that is singleton and its responsible for reading and writting to the database file. why do i still care about locking?
 
Ranch Hand
Posts: 169
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi;

so there are more than one client will access this class and use the
methods provide ex
bookRecord :
1- read record to check if exist.
2- check if the record available for book
3- book the record.

if two clients use this method at the same time may be cause logical error
in the database. also the locking is business issue !.

best regards.
Mohamed darim
 
fei lin
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i synchronize this method. its 1 atomic action.
 
Ranch Hand
Posts: 125
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Fei, synchronizing the entire method, while technically could work, you need to take into consideration performance. Imagine a scenario where many threads are vying for access to the methods of your object. Each of them having to wait for the entire method to execute before they could possibly have their turn, would invariably result in poor performance. The best approach with multi-threaded programming is to synchronize only the resources that's state can be affected by multiple threads. This could be the RandomAccessFile object in your data class, or some sort of map object in a locking class. This approach does require you to think carefully about your design, but the improvements in performance are well worth it. Hope this helps.
 
mohamed sulibi
Ranch Hand
Posts: 169
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi;

thank Mike Ottinger to your reply, another reason that the DB interface is
general interface and does not provide contract that any clients must
synchronized prior to use.

Best regards.
Mohamed Darim.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic