Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

B&S: Locking Question

 
hatim osman
Ranch Hand
Posts: 105
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi...
I am too sorry for asking another question on this issue, but it's killing me, everytime I finish my Data class something comes up. I am very confused about the exceptions thrown from the locking and Crude methods. Which of the following is right:

OR:


I know that both code fragments may look similar, but if you dig deeper, you will see that the second lock() method will only grant locks to records that are valid, since it ensures the validity of the record after waiting. Hence, the delete, update and unlock methods will never throw RecordNotFoundException, since it'all been taken care of in the lock() method "is that right?". Meanwhile, the first lock() method may grant a cookie that points to a record that became invalid after waiting on it, in this case other methods will be capable of throwing RecordNotFoundException when the same cookie is used. My point is, why would the lock() method return a cookie to a record that became invalid as a result of waiting?
Finally, which is a right :
1. lock: check if record is valid---->wait if necessary---->return cookie
2. lock: wait if necessary---->check if record is valid---->return cookie

I am too sorry for propagating this issue again, but I would appreciated if you can help.

Hatim
 
hatim osman
Ranch Hand
Posts: 105
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi...
So stupid of me, I know now when the crud methods can throw RecordNotFoundException:
1. lock 5
2. delete 5
3 try to delete 5 "RecordNotFoundException"

Thanx
 
Andrew Monkhouse
author and jackaroo
Marshal Commander
Pie
Posts: 11911
207
C++ Firefox Browser IntelliJ IDE Java Mac Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Hatim
Meanwhile, the first lock() method may grant a cookie that points to a record that became invalid after waiting on it
This possibility is something you should be concerned about, and I think that it rules out the possibility of the first option.

Regards, Andrew
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic