| ISemaphoreTryAcquire Method (Int32, Int64, TimeUnit) |
Acquires the given number of permits, if they are available and
returns immediately, with the value
true
,
reducing the number of available permits by the given amount.
Namespace:
Hazelcast.Core
Assembly:
Hazelcast.Net (in Hazelcast.Net.dll) Version: 3.12.3
Syntax bool TryAcquire(
int permits,
long timeout,
TimeUnit unit
)
Function TryAcquire (
permits As Integer,
timeout As Long,
unit As TimeUnit
) As Boolean
bool TryAcquire(
int permits,
long long timeout,
TimeUnit unit
)
abstract TryAcquire :
permits : int *
timeout : int64 *
unit : TimeUnit -> bool
Parameters
- permits
- Type: SystemInt32
the number of permits to acquire - timeout
- Type: SystemInt64
the maximum time to wait for the permits - unit
- Type: Hazelcast.CoreTimeUnit
the time unit of the
timeout
argument
Return Value
Type:
Booleantrue
if all permits were acquired and
false
if the waiting time elapsed before all permits could be acquired
Exceptions Exception | Condition |
---|
Exception | if the current thread is interrupted |
ArgumentException |
if
permits
is negative
|
InvalidOperationException | if hazelcast instance is shutdown while waiting |
Remarks
Acquires the given number of permits, if they are available and
returns immediately, with the value
true , reducing the number of available permits by the given amount.
If insufficient permits are available then
the current thread becomes disabled for thread scheduling
purposes and lies dormant until one of three things happens:
-
Some other thread invokes the
Release()
method for this
semaphore and the current thread is next to be assigned a permit; or
-
Some other thread
interrupts
the current thread; or
- The specified waiting time elapses.
If the permits are acquired then the value
true
is returned.
If the specified waiting time elapses then the value
false
is returned. If the time is less than or equal to zero, the method
will not wait at all.
If the current thread is interrupted
while waiting for a permit,
then System.Exception
is thrown and the current thread's
interrupted status is cleared.
See Also