다음을 통해 공유


AbstractQueuedLongSynchronizer.TryAcquireNanos(Int64, Int64) Method

Definition

Attempts to acquire in exclusive mode, aborting if interrupted, and failing if the given timeout elapses.

[Android.Runtime.Register("tryAcquireNanos", "(JJ)Z", "")]
public bool TryAcquireNanos (long arg, long nanosTimeout);
[<Android.Runtime.Register("tryAcquireNanos", "(JJ)Z", "")>]
member this.TryAcquireNanos : int64 * int64 -> bool

Parameters

arg
Int64

the acquire argument. This value is conveyed to #tryAcquire but is otherwise uninterpreted and can represent anything you like.

nanosTimeout
Int64

the maximum number of nanoseconds to wait

Returns

true if acquired; false if timed out

Attributes

Exceptions

if the current thread is interrupted

Remarks

Attempts to acquire in exclusive mode, aborting if interrupted, and failing if the given timeout elapses. Implemented by first checking interrupt status, then invoking at least once #tryAcquire, returning on success. Otherwise, the thread is queued, possibly repeatedly blocking and unblocking, invoking #tryAcquire until success or the thread is interrupted or the timeout elapses. This method can be used to implement method Lock#tryLock(long, TimeUnit).

Java documentation for java.util.concurrent.locks.AbstractQueuedLongSynchronizer.tryAcquireNanos(long, long).

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Applies to