File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "Reading a locked record." Watch "Reading a locked record." New topic

Reading a locked record.

Kasper Friis Kjaerhus

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:

Roel De Nijs

Joined: Jul 19, 2004
Posts: 8371

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,

SCJA, SCJP (1.4 | 5.0 | 6.0), SCJD
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

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:
subject: Reading a locked record.
jQuery in Action, 3rd edition