|
ProgramixGenericLib v5.0.1 | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.programix.thread.Counter
public class Counter
This class serves as a thread-safe integer counter. In fact, there's
no requirement that the value only increment or decrement—the
value can hop around to any value by using setCount(int)
.
Constructor Summary | |
---|---|
Counter()
Creates a counter that starts off with a value of 0. |
|
Counter(int initialCount)
Creates a counter that starts off with the specified initialCount. |
|
Counter(int initialCount,
Object lockObject)
Creates a counter that starts off with the specified initialCount. |
|
Counter(int initialCount,
Waiter waiter)
Creates a counter that starts off with the specified initialCount. |
|
Counter(Object lockObject)
Creates a counter that starts off with a value of 0. |
Method Summary | |
---|---|
Waiter.Condition |
createAtLeastCondition(int minCount)
Returns a Waiter.Condition that can be used to
wait while or wait until the count is greater than or equal
to the specified minCount. |
Waiter.Condition |
createAtMostCondition(int maxCount)
Returns a Waiter.Condition that can be used to
wait while or wait until the count is less than or equal
to the specified maxCount. |
Waiter.Condition |
createCondition(Waiter.Expression expression)
Returns a Waiter.Condition that can be used to
wait while or wait until the the specified expression is true. |
Waiter.Condition |
createRangeCondition(int min,
int max)
Returns a Waiter.Condition that can be used to
wait while or wait until the count is within the specified
range (inclusive of the min and max). |
void |
decrement()
|
boolean |
decrementIfNotShutdown()
Potentially decrements the counter returning true if the counter was decremented or false is the counter was not changed because it's already been shutdown. |
int |
getCount()
|
Object |
getLockObject()
|
Waiter |
getWaiter()
|
void |
increment()
|
boolean |
incrementIfNotShutdown()
Potentially increments the counter returning true if the counter was incremented or false is the counter was not changed because it's already been shutdown. |
boolean |
isNotZero()
|
boolean |
isShutdown()
|
boolean |
isZero()
|
void |
setCount(int newCount)
|
void |
shutdown()
Called to shutdown all access to this counter and to dislodge any threads waiting on conditions. |
void |
waitUntilNegative()
Waits until the count is a negative number (less than zero). |
void |
waitUntilNegative(long msTimeout)
Waits until the count is a negative number (less than zero). |
void |
waitUntilPositive()
Waits until the count is a positive number (greater than zero). |
void |
waitUntilPositive(long msTimeout)
Waits until the count is a positive number (greater than zero). |
void |
waitUntilZero()
Waits until the count is exactly zero. |
void |
waitUntilZero(long msTimeout)
Waits until the count is exactly zero. |
void |
waitWhileNegative()
Waits while the count is a negative number (less than zero). |
void |
waitWhileNegative(long msTimeout)
Waits while the count is a negative number (less than zero). |
void |
waitWhilePositive()
Waits while the count is a positive number (greater than zero). |
void |
waitWhilePositive(long msTimeout)
Waits while the count is a positive number (greater than zero). |
void |
waitWhileZero()
Waits while the count is exactly zero. |
void |
waitWhileZero(long msTimeout)
Waits while the count is exactly zero. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public Counter(int initialCount, Waiter waiter)
initialCount
- the starting value.waiter
- the Waiter
to use.
If null, then a new Waiter
is automatically created.public Counter(int initialCount, Object lockObject)
initialCount
- the starting value.lockObject
- the object to synchronize on.
If null, the the synchronization will be on this instance.public Counter(int initialCount)
initialCount
- the starting value.public Counter(Object lockObject)
lockObject
- the object to synchronize on.
If null, the the synchronization will be on this instance.public Counter()
Method Detail |
---|
public int getCount() throws ShutdownException
ShutdownException
public void setCount(int newCount) throws ShutdownException
ShutdownException
public void increment() throws ShutdownException
ShutdownException
public boolean incrementIfNotShutdown()
public void decrement() throws ShutdownException
ShutdownException
public boolean decrementIfNotShutdown()
public boolean isZero() throws ShutdownException
ShutdownException
public boolean isNotZero() throws ShutdownException
ShutdownException
public void waitWhileZero(long msTimeout) throws TimedOutException, ShutdownException, InterruptException
TimedOutException
ShutdownException
InterruptException
public void waitWhileZero() throws ShutdownException, InterruptException
ShutdownException
InterruptException
public void waitUntilZero(long msTimeout) throws TimedOutException, ShutdownException, InterruptException
TimedOutException
ShutdownException
InterruptException
public void waitUntilZero() throws ShutdownException, InterruptException
ShutdownException
InterruptException
public void waitWhilePositive(long msTimeout) throws TimedOutException, ShutdownException, InterruptException
TimedOutException
ShutdownException
InterruptException
public void waitWhilePositive() throws ShutdownException, InterruptException
ShutdownException
InterruptException
public void waitUntilPositive(long msTimeout) throws TimedOutException, ShutdownException, InterruptException
TimedOutException
ShutdownException
InterruptException
public void waitUntilPositive() throws ShutdownException, InterruptException
ShutdownException
InterruptException
public void waitWhileNegative(long msTimeout) throws TimedOutException, ShutdownException, InterruptException
TimedOutException
ShutdownException
InterruptException
public void waitWhileNegative() throws ShutdownException, InterruptException
ShutdownException
InterruptException
public void waitUntilNegative(long msTimeout) throws TimedOutException, ShutdownException, InterruptException
TimedOutException
ShutdownException
InterruptException
public void waitUntilNegative() throws ShutdownException, InterruptException
ShutdownException
InterruptException
public Waiter.Condition createAtLeastCondition(int minCount)
Waiter.Condition
that can be used to
wait while or wait until the count is greater than or equal
to the specified minCount.
public Waiter.Condition createAtMostCondition(int maxCount)
Waiter.Condition
that can be used to
wait while or wait until the count is less than or equal
to the specified maxCount.
public Waiter.Condition createRangeCondition(int min, int max)
Waiter.Condition
that can be used to
wait while or wait until the count is within the specified
range (inclusive of the min and max).
public Waiter.Condition createCondition(Waiter.Expression expression)
Waiter.Condition
that can be used to
wait while or wait until the the specified expression is true.
public Waiter getWaiter()
public void shutdown()
public boolean isShutdown()
public Object getLockObject()
|
ProgramixGenericLib v5.0.1 | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |