Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

synchronizing findByCriteria() and readRecord() methods?

 
Harry Henriques
Ranch Hand
Posts: 206
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 9828
103
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Harry Henriques
Ranch Hand
Posts: 206
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 9828
103
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic