All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.bdware.dogp.sample.RecvCounter Maven / Gradle / Ivy

The newest version!
package org.bdware.dogp.sample;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import java.util.concurrent.atomic.AtomicInteger;

public class RecvCounter extends Thread {
    static Logger LOGGER = LogManager.getLogger(RecvCounter.class);
    AtomicInteger i;
    String tag;


    public RecvCounter(String tag) {
        this.tag = tag;
        i = new AtomicInteger(0);
    }

    @Override
    public void run() {
        for (; ; ) {
            long pre = System.currentTimeMillis();
            int preCount = i.get();
            try {
                Thread.sleep(5000);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
            LOGGER.info(tag + " RECV:" + i.get() + " deltaTPS:" + (i.get() - preCount) * 1000 / (System.currentTimeMillis() - pre));
        }
    }

    public void inc() {
        i.incrementAndGet();
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy