Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Reading a locked record.

 
Kasper Friis Kjaerhus
Greenhorn
Posts: 2
Chrome IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 9926
111
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Elchin Asgarli
Ranch Hand
Posts: 222
Chrome Eclipse IDE Google Web Toolkit
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I had ReadWriteLock on my data access layer, which would control RandomAccessFile, but that had nothing to do with locks of Data class.
 
Kasper Friis Kjaerhus
Greenhorn
Posts: 2
Chrome IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic