@ThreadSafe public enum FileLocks extends 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 | Method and Description |
|---|---|
static boolean |
isFileLocked(File file)
Returns true if the specified file is currently locked; false otherwise.
|
static boolean |
lock(File file)
Acquires an exclusive lock on the specified file, creating the file as
necessary.
|
static boolean |
unlock(File file)
Unlocks a file previously locked via
lock(File). |
static FileLocks |
valueOf(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.
|
public static FileLocks[] values()
for (FileLocks c : FileLocks.values()) System.out.println(c);
public static FileLocks valueOf(String name)
name - the name of the enum constant to be returned.IllegalArgumentException - if this enum type has no constant with the specified nameNullPointerException - if the argument is nullpublic static boolean lock(File file)
unlock(File) method to prevent release leakage.FileLockException - if we failed to lock the filepublic static boolean isFileLocked(File file)
public static boolean unlock(File file)
lock(File).