wood burning stoves 2.0*
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes confusion - unlock and delete Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "confusion - unlock and delete" Watch "confusion - unlock and delete" New topic
Author

confusion - unlock and delete

Makeshkumar Subramaniam
Greenhorn

Joined: Aug 09, 2008
Posts: 21

hi,
I've just started with this URLyBird assignment. I'm implementing methods

unlock(rec, cookie) throws RecordNotFoundException,SecurityException
and
delete(rec, cookie) throws RecordNotFoundException,SecurityException.

i wonder what if following scenario happens.

consider the following code:



as unlock() is throwing RecordNotFoundException, I'm checking if the given recNo is valid one (using record flag) before unlocking the record(removing this record entry from lock map).

my question is: since record 10 is already deleted. when the control reaches data.unlock(10,c), RecordNotFoundException would be thrown. is it okay ?? or should I change the code as to check record-valid after unlocking, i mean removing recordNo entry from lock map?.

thanks in advance.


cheers,
Makesh.

[URLyBird1.1.1 - > just started]
Roel De Nijs
Bartender

Joined: Jul 19, 2004
Posts: 5121
    
  12

My unlock-method does not contain any check to see if recNo is valid, because that makes no sense. The RecordNotFoundException is only thrown by the lock (and find) method(s).


SCJA, SCJP (1.4 | 5.0 | 6.0), SCJD
http://www.javaroe.be/
Roberto Perillo
Bartender

Joined: Dec 28, 2007
Posts: 2258
    
    3

Roel De Nijs wrote:My unlock-method does not contain any check to see if recNo is valid, because that makes no sense.


Agreed.

Makeshkumar, what you can do is verify if the record to be unlocked was locked (or, if it is in the structure that keeps the locked records - normally a Map<Long, Long>); if it wasn't, then you can throw IllegalStateException.


Cheers, Bob "John Lennon" Perillo
SCJP, SCWCD, SCJD, SCBCD - Daileon: A Tool for Enabling Domain Annotations
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: confusion - unlock and delete
 
Similar Threads
Locking strategy URLyBird 1.1.1 with ReentrantLock
Should delete() also remove the entry from the lock map?
double lock + wait logic?
B&S: unlock() method
Locking & Threading Issues...HELP!