aspose file tools*
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes Reading a locked record. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "Reading a locked record." Watch "Reading a locked record." New topic
Author

Reading a locked record.

Kasper Friis Kjaerhus
Greenhorn

Joined: Jan 21, 2011
Posts: 2

Hi there...

I am currently working on UrlyBird 1.2.3. And have a question that may also apply to other asignments.

Will it be correct to wait for a locked record to become unlocked before i read from it?

My interface specifies this on reads:




SCJP
Roel De Nijs
Bartender

Joined: Jul 19, 2004
Posts: 5596
    
  15

Hi Kasper,

Welcome to the JavaRanch!

I guess that will have an enormous performance decrease. When reading records I didn't care about a record being locked or not. Every valid (= not deleted) record is read immediately, without waiting until it is unlocked.

Kind regards,
Roel


SCJA, SCJP (1.4 | 5.0 | 6.0), SCJD
http://www.javaroe.be/
Elchin Asgarli
Ranch Hand

Joined: Mar 08, 2010
Posts: 222

I had ReadWriteLock on my data access layer, which would control RandomAccessFile, but that had nothing to do with locks of Data class.


Personal page, SCJP 6 with 91%, SCWCD 5 with 84%, OCMJD
Kasper Friis Kjaerhus
Greenhorn

Joined: Jan 21, 2011
Posts: 2

I chose a solution where i read locked records, but have synchronized access to my data. In this way data can be dirty in the application, but it will never be dirty upon read.

I also have made a record comparator, so i can compare the data shown, after a search with data in the "database", this way i can check if data has been changed.

So when you are going to make a booking of a room, you lock the record, compare and update your data, and the user will be presented with a choice to continue booking if data has been changed from the search to the booking.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Reading a locked record.