If the lock is not available then the current thread doesn't wait and returns false immediately.
Warning:
This method uses hashCode and equals of binary form of the key, not the actual implementations of hashCode and equals defined in key's class. @param key key to lock. @return true if lock is acquired, false otherwise. @throws NullPointerException if the specified key is nullIf the lock is not available then the current thread doesn't wait and returns false immediately.
Warning:
This method uses hashCode and equals of binary form of the key, not the actual implementations of hashCode and equals defined in key's class.
@param key key to lock. @return true if lock is acquired, false otherwise.This is a convenience method for attempting to acquire a maximum length lock on the file. It is equivalent to:
fileChannel.tryLock(0L, Long.MAX_VALUE, false)
The method returns null
if the acquisition would result in an overlapped lock with another OS process.
null
if the lock wouldoverlap an existing exclusive lock in another OS process.
@throws ClosedChannelException the file channel is closed.
@throws OverlappingFileLockException Either a lock is already held that overlaps this lock request, or another thread is waiting to acquire a lock that will overlap with this request.
@throws IOException if any I/O error occurs
Acquires the lock if it is not held by another thread and returns immediately with the value {@code true}, setting the lock hold count to one. Even when this lock has been set to use a fair ordering policy, a call to {@code tryLock()} willimmediately acquire the lock if it is available, whether or not other threads are currently waiting for the lock. This "barging" behavior can be useful in certain circumstances, even though it breaks fairness. If you want to honor the fairness setting for this lock, then use {@link #tryLock(long,TimeUnit) tryLock(0, TimeUnit.SECONDS) }which is almost equivalent (it also detects interruption).
If the current thread already holds this lock then the hold count is incremented by one and the method returns {@code true}.
If the lock is held by another thread then this method will return immediately with the value {@code false}. @return {@code true} if the lock was free and was acquired by thecurrent thread, or the lock was already held by the current thread; and {@code false} otherwise
true
if it now has the lock, and false
if it did not acquire the lock. If this acquires the lock on the file, the caller must use {@link #release()} to release the lock.
@returntrue
if it acquired the lock, false otherwise.
@throws IOException
tryLock
is the same as lock
except it returns a boolean indicating whether the lock was granted instead of generating an exception.
@param obj The object to acquire a lock on.
@param lockMode The lock mode to acquire. The lock modes are READ
,UPGRADE
, and WRITE
.
@return True if the lock has been acquired, otherwise false.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|