public class SimpleNonBlockingSemaphore extends Object implements NonBlockingSemaphore
| Modifier and Type | Class and Description |
|---|---|
static class |
SimpleNonBlockingSemaphore.Factory
A concrete factory that can create instances of
SimpleNonBlockingSemaphore. |
| Constructor and Description |
|---|
SimpleNonBlockingSemaphore(String name,
int maxResources)
Creates a
SimpleNonBlockingSemaphore with the given name and number of resources. |
| Modifier and Type | Method and Description |
|---|---|
boolean |
acquire()
Acquires a resource if available.
|
boolean |
acquire(int resources)
Acquires the specified number of resources if they all are available.
|
boolean |
release()
Releases a resource returning it to this semaphore.
|
boolean |
release(int resources)
Releases the specified number of resources returning it to this semaphore.
|
public SimpleNonBlockingSemaphore(String name, int maxResources)
SimpleNonBlockingSemaphore with the given name and number of resources.name - the name of this semaphoremaxResources - the number of resourcespublic boolean acquire()
NonBlockingSemaphore
An invocation of this method yields exactly the same result as acquire(1)
acquire in interface NonBlockingSemaphoretrue if the resource has been acquired; false otherwise.public boolean acquire(int resources)
NonBlockingSemaphoreacquire in interface NonBlockingSemaphoretrue if all the requested resources have been acquired; false otherwise.public boolean release()
NonBlockingSemaphore
An invocation of this method yields exactly the same result as release(1)
release in interface NonBlockingSemaphoretrue if the resource has been released; false otherwise.public boolean release(int resources)
NonBlockingSemaphorerelease in interface NonBlockingSemaphoretrue if all the requested resources have been released; false otherwise.Copyright © 2018. All rights reserved.