public class AtomicCounter extends Object implements Counter
Counter that uses an AtomicLong for its value.
THREAD SAFETY - This classes uses AtomicLong under the covers to ensure consistent reads and writes of value
| Modifier and Type | Field and Description |
|---|---|
protected String |
name |
protected AtomicLong |
value |
| Constructor and Description |
|---|
AtomicCounter(String name) |
AtomicCounter(String name,
AtomicLong atomicLongRef)
This constructor takes a reference to an AtomicLong that may be outside this Counter.
|
AtomicCounter(String name,
long value) |
| Modifier and Type | Method and Description |
|---|---|
long |
addAndGet(long delta)
Adds the delta value to the current value and returns the new value.
|
int |
compareTo(Instrument that) |
String |
getName() |
long |
getValue() |
long |
incrementAndGet()
Returns the new value after one has been added to the Counter.
|
String |
toString() |
protected final AtomicLong value
protected final String name
public AtomicCounter(String name)
public AtomicCounter(String name, long value)
public AtomicCounter(String name, AtomicLong atomicLongRef)
name - the name of the counteratomicLongRef - the reference to an AtomicLongpublic long incrementAndGet()
CounterincrementAndGet in interface Counterpublic long addAndGet(long delta)
Counterpublic String getName()
getName in interface Instrumentpublic long getValue()
getValue in interface Instrumentpublic int compareTo(Instrument that)
compareTo in interface Comparable<Instrument>Copyright © 2016 Atlassian. All rights reserved.