Lines 55-68
Link Here
|
55 |
* Normally this is sufficient protection. If you really need an atomic read, you may |
55 |
* Normally this is sufficient protection. If you really need an atomic read, you may |
56 |
* simply lock the file, perform the read, and unlock it when done. The file will still |
56 |
* simply lock the file, perform the read, and unlock it when done. The file will still |
57 |
* be protected against writes, although the read operation did not request a lock. |
57 |
* be protected against writes, although the read operation did not request a lock. |
58 |
* |
58 |
* <p/> |
|
|
59 |
* The {@code FileLock} implements {@link AutoCloseable}, so it can be created within |
60 |
* try-with-resources resource clause and the lock will be released at the end of the try block. |
61 |
* |
59 |
* @see FileObject |
62 |
* @see FileObject |
60 |
* |
63 |
* @since 9.2 implements {@code AutoCloseable} interface. |
61 |
* @author Petr Hamernik, Jaroslav Tulach, Ian Formanek |
64 |
* @author Petr Hamernik, Jaroslav Tulach, Ian Formanek |
62 |
* @version 0.16, Jun 5, 1997 |
65 |
* @version 0.16, Jun 5, 1997 |
63 |
* |
66 |
* |
64 |
*/ |
67 |
*/ |
65 |
public class FileLock { // XXX JDK 7: implements AutoCloseable |
68 |
public class FileLock implements AutoCloseable { |
66 |
// ========================= NONE file lock ===================================== |
69 |
// ========================= NONE file lock ===================================== |
67 |
|
70 |
|
68 |
/** Constant that can be used in filesystems that do not support locking. |
71 |
/** Constant that can be used in filesystems that do not support locking. |
Lines 109-114
Link Here
|
109 |
locked = false; |
112 |
locked = false; |
110 |
} |
113 |
} |
111 |
|
114 |
|
|
|
115 |
/** |
116 |
* Releases the lock. Equivalent to {@link #releaseLock} call. |
117 |
*/ |
118 |
@Override |
119 |
public final void close() { |
120 |
releaseLock(); |
121 |
} |
122 |
|
112 |
// End of the original part |
123 |
// End of the original part |
113 |
// ============================================================================ |
124 |
// ============================================================================ |
114 |
|
125 |
|