|
Alex (SCJP 1.4, SCBCD 1.3, SCWCD 1.4, SCJD 1.4)
Alex (SCJP 1.4, SCBCD 1.3, SCWCD 1.4, SCJD 1.4)
Is it really necessary for your server to support different database files at the same time? The assignment is pretty clear that there is a single database that you are supposed to use....to let the user pick the database
what if 2 clients try to simultaneously create a record
and deletion (What if... client A locks record 2, then deletes record 2, then client B creates a new record, which goes in at record 2... hopefully record 2 will not still be in the lock list)
Alex (SCJP 1.4, SCBCD 1.3, SCWCD 1.4, SCJD 1.4)
I assume that either you are using a sockets based aproach or that all these operations are being called within one RMI method?Originally posted by Alex Sharkoff
first of all client asks db to lock the record, then client asks db to modify this record, then clients asks db to unlock the record. Having such contract allows to ensure that a thread that is unlocking a record is the same thread that's locked it.
Have you considered having one meta-collection containing dbFileName as the key and a collection as the value? This would mean that you are not continually adding a key that is a concatenation of dbFileName and record number. Your current way of doing this could require a very long key, since it would presumably need a fully qualified dbFileName in case you have files in different directories with the same name.Originally posted by Alex Sharkoff
Some of the databases in the 80s (dBase, FoxPro) used to have the ability to reuse space as a separate function: The usual process would be to take the database down at night, back it up, then run the "compress" function to reuse any space caused by deleted records. Worked quite well as long as there was no 24*7 requirement. Unfortunately the Data class doesn't seem to have suitable methods for defragmenting the data file .Originally posted by Lara McCarver
Also, think about how you are going to handle record creation ...
Originally posted by Alex Sharkoff
// Creates a new record in the database (possibly reusing a// deleted entry)
The Sun Certified Java Developer Exam with J2SE 5: paper version from Amazon, PDF from Apress, Online reference: Books 24x7 Personal blog
Bear in mind that I have a tendency to accept solutions unless I believe they are making a critical mistake. This can mean that I rarely say that something is beyond specifications (Lara is much better at that than I am).
I assume that either you are using a sockets based aproach or that all these operations are being called within one RMI method?
Have you considered having one meta-collection containing dbFileName as the key and a collection as the value?
In your "<db #lock method>" you are explicitly releasing the lock on the lockedRecords - is this what you are really doing? Or are you just showing the implicit steps?
In your "<db #unlock method>" you do not show any form of verification that the client who locked the record is the same as the client who unlocked the record.
Many candidates get very high scores without worrying about reusing space. But if you do decide to do it, there are some easy solutions, however I will let you think about them before butting in with my thoughts
Alex (SCJP 1.4, SCBCD 1.3, SCWCD 1.4, SCJD 1.4)
Thank you, I try .Originally posted by Alex Sharkoff:
Very cheeky
Well it depends on how well you want to adhere to the interface provided. Check your instructions for lock - they may well have something similar to:To me, this means that Data class itself has to be aware of which client is calling which methods.Originally posted by Andrew Monkhouse:
In your "<db #unlock method>" you do not show any form of verification that the client who locked the record is the same as the client who unlocked the record.
Originally posted by Alex Sharkoff:
Should one take care of such verification? Because there is contract for all database client methods that modify / read a specific db record to always first lock / then modify the record / then unlock the record it ensures that the thread (ie client) that locked the record is the thread (ie same client) that is unlocking it. Am I missing something here ?
The Sun Certified Java Developer Exam with J2SE 5: paper version from Amazon, PDF from Apress, Online reference: Books 24x7 Personal blog
Originally posted by Andrew Monkhouse
Well it depends on how well you want to adhere to the interface provided. Check your instructions for lock...
Originally posted by Lara McCarver
I think they said that the client needs to be able to specify the database if it is in stand-alone mode. And if it is connecting to the server, then the client is supposed to specify the server machine & port number instead. Meanwhile, the "GUI" to the server is supposed to specify which database the server is using.
Originally posted by Alex Sharkoff
Physical locking - ensures that only one thread reads or writes to a database file at any given time
Alex (SCJP 1.4, SCBCD 1.3, SCWCD 1.4, SCJD 1.4)
I need to think about this later, but just a quick thought - are you perhaps reimplementing JDK 5's ReadWriteLock functionality?We could possibly leverage on the strategy used by the Concurrent Versions System by creating .rlock and .wlock files.
The Sun Certified Java Developer Exam with J2SE 5: paper version from Amazon, PDF from Apress, Online reference: Books 24x7 Personal blog
Alex (SCJP 1.4, SCBCD 1.3, SCWCD 1.4, SCJD 1.4)
Politics n. Poly "many" + ticks "blood sucking insects". Tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
|