java.lang.AutoCloseablepublic class FileLock
extends java.lang.Object
implements java.lang.AutoCloseable
FileObject.
Typical usage includes locking the file in the editor on first
modification, and then using this object to ensure exclusive access when
overwriting the file (saving) by using FileObject.getOutputStream(org.openide.filesystems.FileLock).
Also used for renames, deletes, &c.
Note that such locks are only used to protect against concurrent write accesses, and are not used for read operations (i.e. they are not write-one-read-many locks). Normally this is sufficient protection. If you really need an atomic read, you may simply lock the file, perform the read, and unlock it when done. The file will still be protected against writes, although the read operation did not request a lock.
TheFileLock implements AutoCloseable, so it can be created within
try-with-resources resource clause and the lock will be released at the end of the try block.AutoCloseable interface.FileObject| Modifier and Type | Field | Description |
|---|---|---|
protected java.lang.Throwable |
lockedBy |
|
static FileLock |
NONE |
Constant that can be used in filesystems that do not support locking.
|
| Constructor | Description |
|---|---|
FileLock() |
| Modifier and Type | Method | Description |
|---|---|---|
void |
close() |
Releases the lock.
|
void |
finalize() |
Finalize this object.
|
boolean |
isValid() |
Test whether this lock is still active, or released.
|
void |
releaseLock() |
Release this lock.
|
public static final FileLock NONE
protected java.lang.Throwable lockedBy
public void releaseLock()
finally clause.public void close()
releaseLock() call.close in interface java.lang.AutoCloseablepublic boolean isValid()
true if lock is still activepublic void finalize()
releaseLock() to release the lock if the program
for some reason failed to.finalize in class java.lang.ObjectBuilt on April 24 2018. | Portions Copyright 1997-2018 Oracle. All rights reserved.