* releases the lock.
*/
public void testMultipleReadersSingleWrite2()
throws Throwable {
JUnitThread tester1 =
new JUnitThread("testMultipleReaders1") {
public void testBody() {
try {
lockManager.lock(1, txn1, LockType.READ, 0,
false, null);
assertTrue
(lockManager.isOwner(nid, txn1, LockType.READ));
while (lockManager.nWaiters(nid) < 2) {
Thread.yield();
}
lockManager.release(1L, txn1);
} catch (DatabaseException DBE) {
DBE.printStackTrace();
fail("caught DatabaseException " + DBE);
}
}
};
JUnitThread tester2 =
new JUnitThread("testMultipleReaders2") {
public void testBody() {
try {
lockManager.lock(1, txn2, LockType.READ, 0,
false, null);
assertTrue
(lockManager.isOwner(nid, txn2, LockType.READ));
while (lockManager.nWaiters(nid) < 2) {
Thread.yield();
}
lockManager.release(1L, txn2);
} catch (DatabaseException DBE) {
DBE.printStackTrace();
fail("caught DatabaseException " + DBE);
}
}
};
JUnitThread tester3 =
new JUnitThread("testMultipleReaders3") {
public void testBody() {
try {
while (lockManager.nOwners(nid) < 2) {
Thread.yield();
}
lockManager.lock(1, txn3, LockType.WRITE, 0,
false, null);
while (lockManager.nWaiters(nid) < 1) {
Thread.yield();
}
assertTrue
(lockManager.isOwner(nid, txn3, LockType.WRITE));
lockManager.release(1L, txn3);
} catch (DatabaseException DBE) {
DBE.printStackTrace();
fail("caught DatabaseException " + DBE);
}
}
};
JUnitThread tester4 =
new JUnitThread("testMultipleReaders4") {
public void testBody() {
try {
while (lockManager.nWaiters(nid) < 1) {
Thread.yield();
}
lockManager.lock(1, txn4, LockType.READ, 0,
false, null);
assertTrue
(lockManager.isOwner(nid, txn4, LockType.READ));
lockManager.release(1L, txn4);
} catch (DatabaseException DBE) {
DBE.printStackTrace();
fail("caught DatabaseException " + DBE);
}
}
};
tester1.start();
tester2.start();
tester3.start();
tester4.start();
tester1.finishTest();
tester2.finishTest();
tester3.finishTest();
tester4.finishTest();
}