Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

NX: Contractor: About lock method

 
Wayne Yang
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have trouble in determining what to do in lock method. In my Contractor assignment, the declaration of lock method is public int lock(int recNo) throws RecordNotFoundException. What I understand that it means that lock method will throw RecordNotFoundException if the record is not available in DB file. Right? And in my implementation of read, update and other methods, in every method I open the DB file and do the job and close the DB file. However, in the implemention of lock method, do I need to open the DB file and determine whether the record exists and close the DB file before I really lock the record using lockManager.lock() (the record number is put into a static instance of HashMap in class lockManager)? If the record does not exist, RecordNotFoundException is thrown. If so, that means that an operation of reading the DB file has to be done before locking the record. But we need to lock the record before reading this record, don't we? It seems conflicting.
I know that I miss something somewhere. Any help?
 
Philippe Maquet
Bartender
Posts: 1872
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Wayne,
But we need to lock the record before reading this record, don't we? It seems conflicting.

No, just before updating or deleting a record.
Best,
Phil.
 
Vlad Rabkin
Ranch Hand
Posts: 555
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Wayne,
I join to Phil's statement. One more thing: Don't confuse locking and synchronization. Locking only "writes", doesn't mean that you shouldn't care about safe execution of "reads".
Best,
Vlad
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic