aspose file tools*
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes B&S 2.2.2. - Thread Safe Access to File Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "B&S 2.2.2. - Thread Safe Access to File" Watch "B&S 2.2.2. - Thread Safe Access to File" New topic
Author

B&S 2.2.2. - Thread Safe Access to File

Pete Palmer
Ranch Hand

Joined: Oct 21, 2008
Posts: 93
Hi,

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 :-
readRecord()
deleteRecord()
findByCriteria()
createRecord()
updateRecord()

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 ?


Pete
Roel De Nijs
Bartender

Joined: Jul 19, 2004
Posts: 5535
    
  13

Pete,

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
Roel


SCJA, SCJP (1.4 | 5.0 | 6.0), SCJD
http://www.javaroe.be/
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: B&S 2.2.2. - Thread Safe Access to File