Win a copy of Java 9 Revealed this week in the Features new in Java 9 forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

how to detect duplicate record number in creation  RSS feed

 
Yan Zhou
Ranch Hand
Posts: 137
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

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.

Thanks.
Yan
 
Mark Spritzler
ranger
Sheriff
Posts: 17309
11
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

Mark
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!