public class Counter extends Object
| Modifier and Type | Field and Description | 
|---|---|
protected ReentrantLock | 
lock
Synchronization lock. 
 | 
protected int | 
start
The counter's start value. 
 | 
protected int | 
value
The counter's value. 
 | 
| Constructor and Description | 
|---|
Counter()
Creates a new Counter instance. 
 | 
Counter(int startValue)
Creates a new Counter instance. 
 | 
| Modifier and Type | Method and Description | 
|---|---|
int | 
decrement()
Decrements the counter by 1. 
 | 
int | 
decrement(int val)
Decrements the counter by val. 
 | 
int | 
getValue()
Returns the value of the counter. 
 | 
int | 
increment()
Increments the counter by 1. 
 | 
int | 
increment(int val)
Increments the counter by val. 
 | 
void | 
reset()
Resets the counter to the start value. 
 | 
void | 
setValue(int val)
Sets the value of the counter. 
 | 
String | 
toString()
API method. 
 | 
protected ReentrantLock lock
protected int value
protected int start
public Counter()
public Counter(int startValue)
startValue - the start value of the counter, 0 by default.public void reset()
public void setValue(int val)
val - the new value.public int getValue()
public int increment()
public int increment(int val)
val - the value by which to increment the counter.public int decrement()
public int decrement(int val)
val - the value by which to decrement the counter.Copyright © GigaSpaces.