All Downloads are FREE. Search and download functionalities are using the official Maven repository.

aQute.libg.filelock.DirectoryLock Maven / Gradle / Ivy

Go to download

A command line utility and Ant plugin to wrap, build, or examine bundles.

There is a newer version: 2.4.0
Show newest version
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