• 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:

Should I synchronize on data in bookHotel method?

 
Ranch Hand
Posts: 81
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Do I need to synchronize on data in my client GUIController method BookHotel?

I already synchronize on my low level class , FileIO which Data implements

 
Ranch Hand
Posts: 1033
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I don't synchronize at that level, the question to ask yourself is "what resource am I protecting from multiple accesses?". In my implementation only a single thread accesses a Data instance at a time. That thread is the thread that is performing actions for the client over the network.

All the syncronization is in the lower level objects that represents the database file and the lock manager.

I syncronize on the RandomAccessFile instance to prevent problems where one thread moves the file pointer and another moves it elsewhere before it can read or write the data.

I also synchronize on the Map of locked resources and the Lock object that is waiting or being notified.

All this is carefully done to ensure that the order is always Map->Lock or Map->RandomAccessFile, never the other way around, so there is no danger of deadlock.
 
Sean Gildea
Ranch Hand
Posts: 81
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks peter!

That answers my question!
 
reply
    Bookmark Topic Watch Topic
  • New Topic