Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

SCJD test locking concept for Bogitt & Scarper

 
James Hungwell
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello all,

I want to discuss this implementation about locking and see what others think. My solution is using RMI. I decided to synchonize on an intern String of the record number; thus it was not necessary to make any DBAccess interface method synchonized except for the createRecord (only one thread accessing the cached database for creating a new record). So inside my methods I have

String recNoString = new Long(recNo).toString().intern();
synchronized(recNoString) {
....
}

Thus when two or more UIs are updating the same record row only one has a lock and the other UI blocks with a (guaranteed) message at the bottom "Obtaining row lock". When the user holding the lock for that row does an update (persist the record) I do a notify on "recNoString" allowing the VM to choose a (rmi) thread to be unblocked. The issue to this is:

1. The 2nd user obtaining a row lock (when the user tabs out of the cell they are editing) is block and thus the UI blocks. Note I give guaranteed feedback that the UI is trying to obtain a row lock. My userguide states that when editing a row, Update as soon as possible because other users will be blocked out.

Even though this approach blocks the other user interfaces, there is no deadlocking and no two threads can possibly update the same record at the same time.

The real question I have is how Sun will test (and how they feel about #1 above). If they test thru my UI, the UI will behave as documented. However if they do a unit test on my Data.java file and in the same thread call lockRecord(x) twice, then on the 2nd invocation their test case will cause a block. However, when using 2 or more UIs simultaneously (or a testcase with 2 or more threads) there is no way this can happen because RMI takes care of using a different thread to invoke methods of the same object on the server.

Thanks for any advice,
James
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic