aQute.libg.filelock.DirectoryLock Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of bnd Show documentation
Show all versions of bnd Show documentation
A command line utility and Ant plugin to wrap, build, or examine bundles.
package aQute.libg.filelock;
import java.io.*;
public class DirectoryLock {
final File lock;
final long timeout;
final public static String LOCKNAME = ".lock";
public DirectoryLock(File directory, long timeout) {
this.lock = new File(directory, LOCKNAME);
this.lock.deleteOnExit();
this.timeout = timeout;
}
public void release() {
lock.delete();
}
public void lock() throws InterruptedException {
if (lock.mkdir())
return;
long deadline = System.currentTimeMillis() + timeout;
while (System.currentTimeMillis() < deadline) {
if (lock.mkdir())
return;
Thread.sleep(50);
}
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy