try {
advisory=new NativeLock(_lock, block);
} catch (Exception e) {
- log.fatal("Failed to create advisory lock file "+_lock,e);
- throw new Error("Failed to create advisory lock file "+_lock);
+ if (!_lock.exists()) {
+ // advisory cannot be created. this is serious.
+ log.fatal("Failed to create advisory lock file "+_lock,e);
+ throw new Error("Failed to create advisory lock file "+_lock);
+ }
}
- return advisory.isLocked();
+ return (advisory!=null) && advisory.isLocked();
}
/**
* call to clear up a filelock file after its been made
*/
private void tidy() {
if (_lock!=null) {
- if ( advisory!=null)
+ if ( advisory!=null) {
+ advisory.target.deleteOnExit(); // release will null the target
advisory.release(true);
- advisory.target.deleteOnExit();
+ }
advisory=null;
_lock=null;
}