• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

NX: Locking for create() ?

 
Nicholas Cheung
Ranch Hand
Posts: 4982
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,
I suddenly think of a case.
For the function:
public int create(String[] data) throws DuplicateKeyException
If the system wants to call this function, should it get a record lock?
If so, how? cos there is no "recNo" as ID becos it will either reuse deleted record, or append it to the end of the file.
Thanks.
Nick.
 
Bill Robertson
Ranch Hand
Posts: 234
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You basically answered this yourself.

If the system wants to call this function, should it get a record lock?
If so, how? cos there is no "recNo" as ID becos it will either reuse deleted record, or append it to the end of the file.

No need for a record lock. Why? There are two cases:
1. Its a new record - So obviously nobody can have it locked unless something crazy is going on with you locking mechanism
2. Its a previous record - Again no need for a lock because the record is not exposed to any client so no client could be working on it which means
it could not be locked. Its free for your taking. And if your locking
is set up correctly then even if there is a delete/create request at the
very same moment on the same record you should still be fine.
 
Bharat Ruparel
Ranch Hand
Posts: 493
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Nick,
Be careful! Your create method still needs to do the writing within a synchronized block on the RAF.
Regards.
Bharat
 
Bill Robertson
Ranch Hand
Posts: 234
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
great point. although the record may not be a concern you
will ALWAYS be concerned with anything that manipulates the file.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic