return false;
}
public void release() {
+ release(true);
+ }
+ public void release(boolean closeChannel) {
try {
- // TODO: verify that channel.close should be called after release() for rigourous locking.
+ // channel.close should be called before release() for rigourous locking.
if (rafile!=null && rafile.getChannel()!=null) {
if (rafile.getChannel().isOpen()) {
+ if (closeChannel && rafile.getChannel().isOpen())
+ rafile.getChannel().close();
if (lock!=null && lock.isValid())
lock.release();
- if (rafile.getChannel().isOpen())
- rafile.getChannel().close();
}
}
} catch (IOException e) {
log.warn("Whilst releasing lock",e);
}
lock=null;
- rafile=null;
+ rafile=null;
}
/**
* @see java.lang.Object#finalize()
*/
protected void finalize() throws Throwable {
- release();
+ release(true); // we explicitly lose the lock here.
+ // log.debug("lock closing through garbage collection ?");
super.finalize();
}