Acquires the lock only if it is not held by another thread at the time of invocation.
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