Assume the DuplicatKeyException is thrown if two threads happen to get the same record number when creating a new record, one thread succeeds in creating the record, how do I detect that the record number is already used, and throws DuplicateKeyException when the second thread attempts to create a record with the same record number?
One way is to wait till writing to file, if the record being written to has valid status during creation, then throws DuplicateKeyException. I do not like this and thought what are other alternatives.
This has been a topic of discussion many times before. It all depends on which assignment you get. If you get the B&S assignment, then it is the Primary Key that is checked and not record number to determine duplicates, In the URLybird assignment there isn't an appparent Primary Key, and makes throwing DuplicateRecordException. I still wouldn't throw it based on record number as two threads shouldn't be able to create records with the same record number.