|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.microsoft.tfs.util.locking.AdvisoryFileLock
public final class AdvisoryFileLock
Provides advisory locking (at minimum, some platforms may escalate to
mandatory) of a filesystem resource. The lock can be held by at most one
thread in a VM, and by only one VM across the computer. This is an
alternative to FileLock
, which is held by all threads in a virtual
machine.
When the lock is created, it is initially held (locked). Make sure to call
release()
to release the lock.
Locks may be used one time only. Once a lock is released it may not be
re-acquired. Call create(File, boolean)
for a new lock.
Method Summary | |
---|---|
static AdvisoryFileLock |
create(java.io.File lockFile,
boolean block)
Creates an AdvisoryFileLock that mediates access to the given
file path. |
boolean |
equals(java.lang.Object obj)
|
protected void |
finalize()
|
int |
hashCode()
|
boolean |
isReleased()
Tests whether this AdvisoryFileLock has been released (via
release() . |
void |
release()
Releases the lock so it can be acquired by other threads/processes. |
Methods inherited from class java.lang.Object |
---|
clone, getClass, notify, notifyAll, toString, wait, wait, wait |
Method Detail |
---|
public static AdvisoryFileLock create(java.io.File lockFile, boolean block) throws java.io.IOException, java.lang.InterruptedException
AdvisoryFileLock
that mediates access to the given
file path. Blocks forever (or until thread interrupted) if block is true,
returns immediately if block if false.
lockFile
- the file to lock (not null). This file does not have to exist, but
it will be created (0 bytes) if it does notblock
- if true, this method does not return until the lock is obtained
(or the controlling thread is interrupted). If false, the method
returns immediately; the value is null if the lock was not
immediately available or an AdvisoryFileLock
if it was.
AdvisoryFileLock
, initially owned. Returns null if and
only if block was set to false and the lock was not immediately
available.
java.io.IOException
- if an error occurred accessing the given lock file path on disk.
java.lang.InterruptedException
- if this thread was interrupted while waiting for its turn to
become the only thread in this VM to lock the given file path.public void release() throws java.io.IOException
java.io.IOException
- if an error occured releasing the underlying operating system
locks.public boolean isReleased()
AdvisoryFileLock
has been released (via
release()
.
protected void finalize() throws java.lang.Throwable
finalize
in class java.lang.Object
java.lang.Throwable
public int hashCode()
hashCode
in class java.lang.Object
public boolean equals(java.lang.Object obj)
equals
in class java.lang.Object
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |