This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes validation of the record in the lock-method Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "validation of the record in the lock-method" Watch "validation of the record in the lock-method" New topic
Author

validation of the record in the lock-method

Elena Taube
Greenhorn

Joined: Dec 06, 2005
Posts: 21
Hello Ranchers,

I am a little bit confused about the validation of the record in the lock- method in Data class.
I have used a Map lockedRecords where the record with the correspondent locked cookie is saved and my lock method looks like this:

Before the record will be locked, it should be checked if it is deleted or not in the database. But what is the correct time to check it: before the synchronisation block (1) or in this block (2).
(1)

(2)


Could you help me ?
any ideas are appreciated!

And thanks a lot!!
Ali Hussain
Ranch Hand

Joined: Jun 19, 2005
Posts: 211
I dont think you needto do either of these two (can be nice to have though).

Third option: It is more important to do this check after the while statement (just before trying to lock the record).


[ December 27, 2005: Message edited by: Ali Hussain ]

- SCEA, SCJD, SCBCD, SCWCD, SCMAD, SCJP, ICAD (WebSphere), Lotus Principal CLP, Lotus CLP, Lotus CLS
Alex Sharkoff
Ranch Hand

Joined: Apr 11, 2004
Posts: 209
Hi Elena and Ali,

Ali said:

I dont think you needto do either of these two (can be nice to have though).

Third option: It is more important to do this check after the while statement (just before trying to lock the record).


I think it's also important to check whether the record exists before entering the synchronized block. Why to wait for the lockedRecords monitor if the record does not exist?



Alex (SCJP 1.4, SCBCD 1.3, SCWCD 1.4, SCJD 1.4)
Ali Hussain
Ranch Hand

Joined: Jun 19, 2005
Posts: 211
I agree with Alex and would do something like this:

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: validation of the record in the lock-method
 
Similar Threads
unlock hangs
My Locking Method: please, advise me.
I passed, but I suffered the 44/80 locking penalty. Why?
lock and wait
Lock question!