File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes synchronizing findByCriteria() and readRecord() methods? 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 "synchronizing findByCriteria() and readRecord() methods?" Watch "synchronizing findByCriteria() and readRecord() methods?" New topic
Author

synchronizing findByCriteria() and readRecord() methods?

Harry Henriques
Ranch Hand

Joined: Jun 17, 2009
Posts: 206
Hi,

My question concerns concurrency and the two methods, findByCriteria() and readRecord(). There is a time lag between "finding" a list of records that meet a set of criteria and "reading" those same records from the database. My implementation of the Data class doesn't use locking/unlocking with the findByCriteria() method, nor does it use locking/unlocking with the readRecord() method. First, findByCriteria() returns a list of records that meet the search criteria, and then, I must use the readRecord() method to read that list of records into my JTable. This is not an atomic operation. Other clients can access the "found" records in the list before I read them from the database file, and these clients can modify/delete records on my list of "found" records.

How did you handle this problem?

Thanks,
Harry
Roel De Nijs
Bartender

Joined: Jul 19, 2004
Posts: 5131
    
  12

Hi Harry,

There are so many threads regarding this issue already in this forum that you certainly can find several of them using the search function. This one is just a few weeks old (take a look at my last post in that thread).

Kind regards,
Roel


SCJA, SCJP (1.4 | 5.0 | 6.0), SCJD
http://www.javaroe.be/
Harry Henriques
Ranch Hand

Joined: Jun 17, 2009
Posts: 206
Hi Roel,

The answer to my question is actually pretty simple. I don't think that this implementation can deadlock at the Business Layer.


Best Regards,

Harry
Roel De Nijs
Bartender

Joined: Jul 19, 2004
Posts: 5131
    
  12

Hi Harry,

That is the 2nd operation I described (the atomic operation), so indeed that should do the job without any deadlock (or RNFE being thrown )

Small remark: the "new Long(recNo)" (line 7) is not needed, you simply can use "recNo" instead (thanks to Java 5 feature boxing)

Kind regards,
Roel
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: synchronizing findByCriteria() and readRecord() methods?
 
Similar Threads
URLyBird: Question about find.
B&S locking issues & findByCriteria
not sure which methods must be synchronized
URLyBird 1.2.2: findByCriteria()
B&S What Are You Guys Passing Into Your findByCriteria For criteria[2] Thru [5]?