RExpirable
, RExpirableAsync
, RObject
, RObjectAsync
, RSemaphoreAsync
RedissonQueueSemaphore
, RedissonSemaphore
public interface RSemaphore extends RExpirable, RSemaphoreAsync
Semaphore
.
Works in non-fair mode. Therefore order of acquiring is unpredictable.
Modifier and Type | Method | Description |
---|---|---|
void |
acquire() |
Acquires a permit from this semaphore, blocking until one is
available, or the thread is interrupted.
|
void |
acquire(int permits) |
Acquires the given number of permits from this semaphore,
blocking until all are available,
or the thread is interrupted.
|
int |
availablePermits() |
Returns the current number of available permits.
|
int |
drainPermits() |
Acquires and returns all permits that are immediately available.
|
void |
reducePermits(int permits) |
Shrinks the number of available permits by the indicated
reduction.
|
void |
release() |
Releases a permit, returning it to the semaphore.
|
void |
release(int permits) |
Releases the given number of permits, returning them to the semaphore.
|
boolean |
tryAcquire() |
Acquires a permit only if one is available at the
time of invocation.
|
boolean |
tryAcquire(int permits) |
Acquires the given number of permits only if all are available at the
time of invocation.
|
boolean |
tryAcquire(int permits,
long waitTime,
TimeUnit unit) |
Acquires the given number of permits only if all are available
within the given waiting time and the current thread has not
been interrupted.
|
boolean |
tryAcquire(long waitTime,
TimeUnit unit) |
Acquires a permit from this semaphore, if one becomes available
within the given waiting time and the current thread has not
been interrupted.
|
boolean |
trySetPermits(int permits) |
Sets number of permits.
|
clearExpire, expire, expireAt, expireAt, remainTimeToLive
clearExpireAsync, expireAsync, expireAtAsync, expireAtAsync, remainTimeToLiveAsync
copy, delete, dump, getCodec, getName, isExists, migrate, move, rename, renamenx, restore, restore, restoreAndReplace, restoreAndReplace, touch, unlink
copyAsync, deleteAsync, dumpAsync, isExistsAsync, migrateAsync, moveAsync, renameAsync, renamenxAsync, restoreAndReplaceAsync, restoreAndReplaceAsync, restoreAsync, restoreAsync, touchAsync, unlinkAsync
acquireAsync, acquireAsync, reducePermitsAsync, releaseAsync, releaseAsync, tryAcquireAsync, tryAcquireAsync, tryAcquireAsync, tryAcquireAsync, trySetPermitsAsync
void acquire() throws InterruptedException
Acquires a permit, if one is available and returns immediately, reducing the number of available permits by one.
If no permit is available then the current thread becomes disabled for thread scheduling purposes and lies dormant until one of two things happens:
release()
method for this
semaphore and the current thread is next to be assigned a permit; or
InterruptedException
- if the current thread is interruptedvoid acquire(int permits) throws InterruptedException
Acquires the given number of permits, if they are available, and returns immediately, 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 two things happens:
release
methods for this semaphore, the current thread is next to be assigned
permits and the number of available permits satisfies this request; or
permits
- the number of permits to acquireInterruptedException
- if the current thread is interruptedIllegalArgumentException
- if permits
is negativeboolean tryAcquire()
Acquires a permit, if one is available and returns immediately,
with the value true
,
reducing the number of available permits by one.
If no permit is available then this method will return
immediately with the value false
.
true
if a permit was acquired and false
otherwiseboolean tryAcquire(int permits)
Acquires a permits, if all are available and returns immediately,
with the value true
,
reducing the number of available permits by given number of permits.
If no permits are available then this method will return
immediately with the value false
.
permits
- the number of permits to acquiretrue
if a permit was acquired and false
otherwiseboolean tryAcquire(long waitTime, TimeUnit unit) throws InterruptedException
Acquires a permit, if one is available and returns immediately,
with the value true
,
reducing the number of available permits by one.
If no permit is available then the current thread becomes disabled for thread scheduling purposes and lies dormant until one of three things happens:
release()
method for this
semaphore and the current thread is next to be assigned a permit; or
If a permit is 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.
waitTime
- the maximum time to wait for a permitunit
- the time unit of the timeout
argumenttrue
if a permit was acquired and false
if the waiting time elapsed before a permit was acquiredInterruptedException
- if the current thread is interruptedboolean tryAcquire(int permits, long waitTime, TimeUnit unit) throws InterruptedException
Acquires a permits, if all are available and returns immediately,
with the value true
,
reducing the number of available permits by one.
If no permit is available then the current thread becomes disabled for thread scheduling purposes and lies dormant until one of three things happens:
release()
method for this
semaphore and the current thread is next to be assigned a permit; or
If a permits is 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.
permits
- amountwaitTime
- the maximum time to wait for a permitunit
- the time unit of the timeout
argumenttrue
if a permit was acquired and false
if the waiting time elapsed before a permit was acquiredInterruptedException
- if the current thread is interruptedvoid release()
Releases a permit, increasing the number of available permits by one. If any threads of Redisson client are trying to acquire a permit, then one is selected and given the permit that was just released.
There is no requirement that a thread that releases a permit must
have acquired that permit by calling acquire()
.
Correct usage of a semaphore is established by programming convention
in the application.
void release(int permits)
Releases the given number of permits, increasing the number of available permits by the given number of permits. If any threads of Redisson client are trying to acquire a permits, then next threads is selected and tries to acquire the permits that was just released.
There is no requirement that a thread that releases a permits must
have acquired that permit by calling acquire()
.
Correct usage of a semaphore is established by programming convention
in the application.
permits
- amountint availablePermits()
int drainPermits()
boolean trySetPermits(int permits)
permits
- - number of permitstrue
if permits has been set successfully, otherwise false
.void reducePermits(int permits)
permits
- - reduction the number of permits to removeIllegalArgumentException
- if reduction
is negativeCopyright © 2014–2018 The Redisson Project. All rights reserved.