File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes Question on findCriteria Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "Question on findCriteria" Watch "Question on findCriteria" New topic

Question on findCriteria

Mikie Williams

Joined: Jan 11, 2005
Posts: 7
I have just written the findCriteria part of my Data class and was wondering if I should be locking the matching records until the search is complete. I ask because say I find a matching record and while I am searching the remianing records another thread comes along and deletes that record my matching record is no longer valid. Any input would be great.

Yevgeniy Treyvus
Ranch Hand

Joined: Mar 09, 2005
Posts: 48
Generally, only methods that actually modify the data should be locking any records. One reason for that is that to find anything will generally mean you will have to loop through all the records. In effect, the find operation will likely be the slowest of all your DB operations (O(n)). Therefore, locking the records in your find operation would mean a significant bottleneck.

If another thread deletes the record while the find operation is retrieving the records, so be it. It just means your data will be a little stale. I don't think there's a problem with that. If for instance, you use the find method within your update method (to find the appropriate method to update) and the find method returns a record that has been deleted by another thread, that would just mean that your update method will have to throw the RecordNotFoundException.
[ April 04, 2005: Message edited by: Yevgeniy Treyvus ]

I agree. Here's the link:
subject: Question on findCriteria
It's not a secret anymore!