}
assertEquals(0, locks);
}
public void run() {
FileLock lock = null;
while (!stop) {
lock = new FileLock(new TraceSystem(null), getFile(), 100);
try {
lock.lock(allowSockets ? FileLock.LOCK_SOCKET : FileLock.LOCK_FILE);
base.trace(lock + " locked");
locks++;
if (locks > 1) {
System.err.println("ERROR! LOCKS=" + locks + " sockets=" + allowSockets);
stop = true;
}
Thread.sleep(wait + (int) (Math.random() * wait));
locks--;
base.trace(lock + " unlock");
lock.unlock();
if (locks < 0) {
System.err.println("ERROR! LOCKS=" + locks);
stop = true;
}
} catch (Exception e) {
// log(id+" cannot lock: " + e);
}
try {
Thread.sleep(wait + (int) (Math.random() * wait));
} catch (InterruptedException e1) {
// ignore
}
}
if (lock != null) {
lock.unlock();
}
}