
com.hecloud.runtime.common.utils.TpsCalculator Maven / Gradle / Ivy
package com.hecloud.runtime.common.utils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.concurrent.atomic.AtomicLong;
/**
* @author LoveinBJ
*/
public class TpsCalculator extends Thread {
public static final AtomicLong tps = new AtomicLong(0L);
private static Logger logger = LoggerFactory.getLogger(TpsCalculator.class);
private boolean running = true;
/**
* 每次请求递增加1
*/
public static void increase() {
tps.incrementAndGet();
}
/**
* 归零
*/
public static void reset() {
tps.set(0);
}
@Override
public void run() {
while (running) {
try {
Thread.sleep(1000L);
} catch (InterruptedException e) {
logger.error("TpsCalculator occur InterruptedException", e);
Thread.currentThread().interrupt();
this.start();
}
reset();
}
}
public void shutdown() {
this.running = false;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy