Win a copy of 97 Things Every Java Programmer Should Know this week in the Java in General forum!
  • 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 ...
  • Campbell Ritchie
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
  • Piet Souris
  • salvin francis
  • fred rosenberger

B&S 2.2.2. - Thread Safe Access to File

Ranch Hand
Posts: 106
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

My Data class uses the Facade Pattern to provide the access to the file ( DatabaseAccess class ) and record locking facility ( LockManger class ).

When the server is started a single instance of the Data class ( and of DatabaseAccess & LockManager) is created to support database access to the many clients.

The DatabaseAccess class provides following methods :-

To ensure access to the database file is thread safe, I could synchronise all the above methods which would be easy and effective or I could introduce “ReadWriteLock” variables so that I could synchronise specific code blocks.

Any reason why I shouldn’t just synchronise all the methods in the DatabaseAccess class ?

Posts: 11604
Hibernate jQuery Eclipse IDE Spring MySQL Database AngularJS Tomcat Server Chrome Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

If you synchronize all methods you will loose a little bit of performance and concurrency. but according to the instructions that's not one of the main requirements.

I synchronized also all my methods in the Data-class and made of course a singleton of the Data-class (like you did)

Kind regards
Good luck
He's giving us the slip! Quick! Grab this tiny ad!
Thread Boost feature
    Bookmark Topic Watch Topic
  • New Topic