This week's giveaway is in the Programmer Certification (OCPJP) forum.
We're giving away four copies of Java Mock Exams (software) and have David Mayer on-line!
See this thread for details.
Win a copy of Java Mock Exams (software) this week in the Programmer Certification (OCPJP) forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

(B&S)Doubt about my read() concept

 
Saheed Adepoju
Ranch Hand
Posts: 267
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all
I am almost done with my read() method and i came into a position where i had to ask for a little advice on my algorithm! I am using a cache for the contractor records! Suppose i want to read a record i would have to do the following:



Well my question is this:
Am i synchronising too much? Or is just ok! I imagined i check if the record value exist and then i also check it is not locked before i now check for the record!
Again, since i know the number of records in my data file and the instruction says to create a new record we check for the byte flag and can reuse the space of the other record that has a byte flag of 0. Could i hard code:


instead of what i have above?
Please an insight would be appreciated!
 
Alex Sharkoff
Ranch Hand
Posts: 209
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Saheed,


sync(reservedRecords){
//wait for the cache if recNo is within the cache
}


Do you mean locked records? Or booked? If booked then it does not belong in the Data class because booking is part of the business logic.

Anyway my personal opinion that it could be just enough to do synchronisation on the actual database file (let the client read the record even when it's locked). This post might be of further assistance to you http://www.coderanch.com/t/187728/java-developer-SCJD/certification/lock-read-or-just-read


Hope it helps.
 
Happiness is not a goal ... it's a by-product of a life well lived - Eleanor Roosevelt. Tiny ad:
the new thread boost feature: great for the advertiser and smooth for the coderanch user
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!