• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

NX: Locking for create() ?

 
Ranch Hand
Posts: 4982
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 234
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 493
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic