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

Record Level Locking Question.

 
Anthony Choi
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For the following Scenario

- Thread1 tries to delete a record
- Thread2 tries to update the same record

If Thread1 get the CPU before Thread2 does, my program deletes the record and throws RecordNotFoundException.

If the excution order is reverse, my program updates and then deletes the record and throws nothing.

Does my program behavior correctly?

Thanks in advance.
 
Alex Belisle Turcot
Ranch Hand
Posts: 516
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by bk choi:
For the following Scenario

- Thread1 tries to delete a record
- Thread2 tries to update the same record

If Thread1 get the CPU before Thread2 does, my program deletes the record and throws RecordNotFoundException.

If the excution order is reverse, my program updates and then deletes the record and throws nothing.

Does my program behavior correctly?

Thanks in advance.


Hi!

Yes it sounds very good to me, depending on where the exception is thrown (while trying to lock or while trying to update).

Does your "lock" method provided by SUN throws RecordNotFoundException ? If so it should not allow to lock a non-existing record.

In so many words, I believe locking should be denied and RecordNotFoundException should be thrown when trying to lock the record that doesn't exist.

Regards,
Alex
 
Mahendran Mohan
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
This is my interpretation of your post.
Scenario-1: Delete-thread locks the record, deletes the record,
Update-thread throws Rec Not Found.
Scenario-2: Update-thread locks, updates the record, delete-thread
throws nothing.

Scenario-1 is OK. Scenario-2, shouldn't delete-thread also throw 'Rec Not Found'?. It should. The following would be OK.

Scenario-2: Update-thread locks, updates the record, delete-thread
throws Rec Not Found.

Cheers, Mahendran
SCJP, SCWCD, SCJD - B&S in progress.
 
Anthony Choi
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you, MahendranMohan and Alex.

You guys are right.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic