aspose file tools*
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes B&S: Locking Question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "B&S: Locking Question" Watch "B&S: Locking Question" New topic
Author

B&S: Locking Question

hatim osman
Ranch Hand

Joined: Jun 10, 2005
Posts: 105
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

Joined: Jun 10, 2005
Posts: 105
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

Joined: Mar 28, 2003
Posts: 11478
    
  94

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


The Sun Certified Java Developer Exam with J2SE 5: paper version from Amazon, PDF from Apress, Online reference: Books 24x7 Personal blog
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: B&S: Locking Question