com.hazelcast.util.counters
Class MwCounter

java.lang.Object
  extended by com.hazelcast.util.counters.MwCounter
All Implemented Interfaces:
Counter

public final class MwCounter
extends Object
implements Counter

A Counter that is thread-safe; so can be incremented by multiple threads concurrently. The MwCounter is not meant for a huge amount of contention. In that case it would be better to create a counter on the LongAdder. This counter does not provide padding to prevent false sharing.


Method Summary
 long get()
          Gets the current value.
 void inc()
          Increments the counter by one.
 void inc(int amount)
          Increments the counter by the given amount.
static MwCounter newMwCounter()
          Creates a new MwCounter with 0 as initial value.
static MwCounter newMwCounter(int initialValue)
          Creates a new MwCounter with the given initial value.
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Method Detail

get

public long get()
Description copied from interface: Counter
Gets the current value.

Specified by:
get in interface Counter
Returns:
the current value.

inc

public void inc()
Description copied from interface: Counter
Increments the counter by one.

Specified by:
inc in interface Counter

inc

public void inc(int amount)
Description copied from interface: Counter
Increments the counter by the given amount. If the amount is negative, the counter is decremented.

Specified by:
inc in interface Counter
Parameters:
amount - the amount to increase the counter with.

toString

public String toString()
Overrides:
toString in class Object

newMwCounter

public static MwCounter newMwCounter()
Creates a new MwCounter with 0 as initial value.


newMwCounter

public static MwCounter newMwCounter(int initialValue)
Creates a new MwCounter with the given initial value.

Parameters:
initialValue - the initial value.


Copyright © 2015 Hazelcast, Inc.. All Rights Reserved.