_conn.getObjectByIdentity(pgOid, LockType.WRITE_LOCK);
// test different LockWaitStrategies
_kit.setLockWaitStrategy(new NoWaitStrategy());
failIfLockForWrite(conn2, pgOid);
_kit.setLockWaitStrategy(new TimeoutStrategy(1));
failIfLockForWrite(conn2, pgOid);
// Second test for the TimeoutStrategy:
// let the second tx to lock
_kit.setLockWaitStrategy(new TimeoutStrategy(2000));
tx2 = _kit.getTransaction(conn2);
tx2.begin();
(new Thread()
{
public void run()
{
try
{
Thread.sleep(1000);
tx3.commit();
}
catch (InterruptedException ex)
{
}
}
}).start();
conn2.getObjectByIdentity(pgOid, LockType.WRITE_LOCK);
tx2.commit();
// Third test for the TimeoutStrategy:
// test deadlock detection
_kit.setLockWaitStrategy(new TimeoutStrategy(4000));
tx = _kit.getTransaction(_conn);
tx.begin();
_conn.getObjectByIdentity(pgOid, LockType.WRITE_LOCK);
tx2 = _kit.getTransaction(conn2);
tx2.begin();