• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Testing Harness

 
GD Deepz
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Does anybody have a good test harness to test the lock/unlock sequence. What excatly are we looking for in the test? Is it that for every thread that goes into a wait mode, it must eventually get a lock otherwise its deadlocked. I wrote a simple test harness. There are five threads but some of the threads are getting deadlocked meaning, they never acquire a lock.

public class LockTesting extends Thread {
private static Data data1;
private static Data data2;

public static void main(String[] args) {
data1 = new Data(); //Is two data Data objects valid

// data2 = new Data();
LockTesting test1 = new LockTesting();
LockTesting test2 = new LockTesting();

LockTesting test3 = new LockTesting();

LockTesting test4 = new LockTesting();
LockTesting test5 = new LockTesting();

test1.start();
test2.start();

test3.start();

test4.start();
test5.start();


/* (non-Javadoc)
* @see java.lang.Runnable#run()
*/
public void run() {
long cookie1 = data1.lockRecord(1);
data1.updateRecord(1, null, cookie1);

}
}
 
Anton Golovin
Ranch Hand
Posts: 476
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, GD! In the run method, the last line should be the unlock method. What is happening now is that some records never get unlocked, and the threads waiting on them wait forever.
 
GD Deepz
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Anton, tks for your reply. In fact I do have a unlock method that is invoked as such:

updataRecord(long recNo, String[] data, long lockCookie){
try { dao.updateDatabase(contractor); //persist to database
} finally {
unlock(recNo, lockCookie); // this unlocks the record
}
}

It goes like this; lock/updateRecord/unlock

Not sure why it is caught in a waiting mode.
 
Mike Vess
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
First of all i think you should update you test-program so that every thread do several updates of the record not just one.



Why are you calling unlock in the updateRecord method?

Now to your question of why some threads are deadlocked. The problem must be in the lock/unlock methods. These methods should be synchronized in some way and whenever you unlock a record you must notify other threads that may be waiting in the lock method.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic