public enum FileLocks extends java.lang.Enum<FileLocks>
Per javadoc of FileLock
, "File locks are held on behalf of the entire
Java virtual machine. They are not suitable for controlling access to a file
by multiple threads within the same virtual machine."
Hence the need for this utility class.
Modifier and Type | Field and Description |
---|---|
private static boolean |
EXTERNAL_LOCK |
private static java.util.Map<java.io.File,java.io.RandomAccessFile> |
lockedFiles |
private static org.apache.commons.logging.Log |
log |
Modifier and Type | Method and Description |
---|---|
static boolean |
isFileLocked(java.io.File file)
Returns true if the specified file is currently locked; false otherwise.
|
static boolean |
lock(java.io.File file)
Acquires an exclusive lock on the specified file, creating the file as
necessary.
|
static boolean |
unlock(java.io.File file)
Unlocks a file previously locked via
lock(File) . |
static FileLocks |
valueOf(java.lang.String name)
Returns the enum constant of this type with the specified name.
|
static FileLocks[] |
values()
Returns an array containing the constants of this enum type, in
the order they are declared.
|
private static final boolean EXTERNAL_LOCK
private static final org.apache.commons.logging.Log log
private static final java.util.Map<java.io.File,java.io.RandomAccessFile> lockedFiles
public static FileLocks[] values()
for (FileLocks c : FileLocks.values()) System.out.println(c);
public static FileLocks valueOf(java.lang.String name)
name
- the name of the enum constant to be returned.java.lang.IllegalArgumentException
- if this enum type has no constant with the specified namejava.lang.NullPointerException
- if the argument is nullpublic static boolean lock(java.io.File file)
unlock(File)
method to prevent release leakage.FileLockException
- if we failed to lock the filepublic static boolean isFileLocked(java.io.File file)
public static boolean unlock(java.io.File file)
lock(File)
.