Example usage for java.util.concurrent.atomic AtomicLong getAndAdd

List of usage examples for java.util.concurrent.atomic AtomicLong getAndAdd

Introduction

In this page you can find the example usage for java.util.concurrent.atomic AtomicLong getAndAdd.

Prototype

public final long getAndAdd(long delta) 

Source Link

Document

Atomically adds the given value to the current value, with memory effects as specified by VarHandle#getAndAdd .

Usage

From source file:okuyama.imdst.util.KeyManagerValueMap.java

private void totalDataSizeCalc(Object key, Object value) {
    if (!ImdstDefine.calcSizeFlg)
        return;//from  ww  w . j  ava  2s . c  om

    long addSize = 0L;

    if (value != null)
        addSize = new Double((((String) key).length() + ((String) value).length()) * 0.8).longValue();

    if (addSize != 0L)
        addSize = addSize + 20;

    String unique = null;
    String keyStr = (String) key;
    int beforeSize = 0;
    AtomicLong size = null;
    int nowValLen = 0;

    if (keyStr.indexOf("#") == 0) {

        unique = keyStr.substring(0, 6);
    } else {
        unique = "all";
    }

    if (mapValueInSize) {
        String val = (String) super.get(key);

        if (val != null) {
            nowValLen = new Double(
                    (((String) key).length() + new Integer(((String[]) val.split(":"))[1]).intValue()) * 0.8)
                            .intValue()
                    + 20;
        }
    } else {

        Object val = this.get(key);

        if (val != null) {
            nowValLen = new Double((((String) key).length() + ((String) val).length()) * 0.8).intValue() + 20;
        }
    }
    if (nowValLen != 0) {
        beforeSize = nowValLen * -1;
    }

    if (!dataSizeMap.containsKey(unique)) {
        size = new AtomicLong(0L);
        dataSizeMap.put(unique, size);
    } else {
        size = (AtomicLong) dataSizeMap.get(unique);
    }

    // ?
    size.getAndAdd(beforeSize);
    size.getAndAdd(addSize);
}