Hi all,
I have started to work my assignment and after a week, I thought I had completed all the classes behind the DB interface. After reading a bit previous threads, I realize my mistakes, but I still have doubts about few things. I would really appreciate if you could help me clear them out.
1- Validity of the synchronization solution
Being new to synchronization, I went for what I thought was the easiest solution : using the synchronized key
word as soon as I suspected
thread concurrency could threaten the consistency of the data. This means that most of my methods uses it soon after their declaration. I am accessing the file with a RandomAccessFile object, and this is on this object that I am synchronizing on. The result of that is each operation is sequential, a thread trying to delete record 2 will have to wait until the thread modifying record 5 releases the lock on the RandomAccessFile object. I was happy with this, ready to document how slow this would be and possible solution, until I read somewhere that this (having a sequential access) would certainly cause me to fail. I cannot not find the thread anymore but I am pretty sure it was on this forum. Can you please confirm ?
The only alternative to this would be to lock the records individually, meaning that I would have to cache the data (which I did not, thinking that modifying the file directly was more solid/reliable).
2- Field are null terminated
I got confused by a paragraph in the assignment saying that the fields are "null terminated if less than the maximum length for the field". In the DB file provided, spaces are written where we should have seen null. So I took the decision to do the same and pad my fields with spaces as per below. Is this something you would recommand ?
tempField being the current
String field, tempByteArray an array of the field expected size, and BLANK_BYTE = ' '
3- Is the value generated by the lock method the one that should be written on the last field of the record ? The assignment specify that this should be an 8 digit number, so I have limited the possible range for the cookie, starting from 10000000 to 99999999.
Thanks in advance. Please let me know if I am breaking any forum rule by posting the code above.
++
Sandrew