- position
- the starting position for the locked region.
- size
- the length of the locked region in bytes.
- shared
- a flag indicating whether an attempt should be made to acquire a shared lock.
Documentation for this section has not yet been entered.
Type Reason Java.Lang.IllegalArgumentException if position or size is negative. Java.Nio.Channels.ClosedChannelException if this channel is closed. Java.Nio.Channels.OverlappingFileLockException if the requested region overlaps an existing lock or pending lock request. Java.Nio.Channels.NonReadableChannelException if the channel is not opened in read-mode but shared is true. Java.Nio.Channels.NonWritableChannelException if the channel is not opened in write mode but shared is false. Java.Nio.Channels.AsynchronousCloseException if this channel is closed by another thread while this method is executing. Java.Nio.Channels.FileLockInterruptionException if the thread is interrupted while in the state of waiting on the desired file lock. Java.IO.IOException if another I/O error occurs.
Obtains a lock on a specified region of the file.
This is the blocking version of lock acquisition, see also the tryLock() methods.
Attempts to acquire an overlapping lock region will fail. The attempt will fail if the overlapping lock has already been obtained, or if another thread is currently waiting to acquire the overlapping lock.
If the request is not for an overlapping lock, the thread calling this method will block until the lock is obtained (likely by no contention or another process releasing a lock), or until this thread is interrupted or the channel is closed.
If the lock is obtained successfully then the Java.Nio.Channels.FileLock object returned represents the lock for subsequent operations on the locked region.
If the thread is interrupted while waiting for the lock, the thread is set to the interrupted state and throws a Java.Nio.Channels.FileLockInterruptionException. If this channel is closed while the thread is waiting to obtain the lock then the thread throws a Java.Nio.Channels.AsynchronousCloseException.
There is no requirement for the position and size to be within the current start and length of the file.
Some platforms do not support shared locks, and if a request is made for a shared lock on such a platform, this method will attempt to acquire an exclusive lock instead. It is undefined whether the lock obtained is advisory or mandatory.