public class ConcurrencyManager extends Object
Under the covers, this object uses a set of named counting semaphores. A calling thread asks for permission by
giving a name to getPermit(String); if no more permits are available on the named semaphore, this manager
will throw a runtime exception. In effect, it will abort a thread unless that thread is permitted to continue.
Because this manager maintains a dynamic set of named counting semaphores, you can have groups of threads that are
allowed to operate independently of other groups of threads (i.e. each group of threads can use their own named
semaphore).
Each counting semaphore will be given a default number of total permits. You can set a custom number of permits per counting semaphore by passing in a set of names with their associated number-of-permits-allowed to the constructor.
| Modifier and Type | Class and Description |
|---|---|
static class |
ConcurrencyManager.Permit |
| Constructor and Description |
|---|
ConcurrencyManager(Map<String,Integer> newPermitsAllowed) |
| Modifier and Type | Method and Description |
|---|---|
Map<String,Integer> |
getAllConfiguredNumberOfPermitsAllowed()
Returns a copy of the map with all named permits and how many are allowed to be concurrently held.
|
int |
getConfiguredNumberOfPermitsAllowed(String name)
If the named semaphore has a configured number-of-permits-allowed (numPermitsAllowed) then the number of permits
allowed is returned.
|
ConcurrencyManager.Permit |
getPermit(String name)
Asks to obtain a permit to continue.
|
void |
releasePermit(ConcurrencyManager.Permit permit)
Returns the permission that was previously granted to the caller.
|
public ConcurrencyManager.Permit getPermit(String name) throws NotPermittedException
name is null, this method will return always (in effect, the null
semaphore allows an unlimited number of permits).name - the name of the semaphore to acquire the permit from (note: this has nothing to do with the name of
a thread or thread group) (may be null)release it.NotPermittedException - if the calling thread cannot obtain a permitpublic void releasePermit(ConcurrencyManager.Permit permit)
permit - the permit that was previously granted that is now being released (may be null)public Map<String,Integer> getAllConfiguredNumberOfPermitsAllowed()
public int getConfiguredNumberOfPermitsAllowed(String name)
name where that name in the map returned by getAllConfiguredNumberOfPermitsAllowed() has no value
- this is due to the fact that this method checks system properties as a fall back.name - the name of the semaphoreCopyright © 2008-2013 Red Hat, Inc.. All Rights Reserved.