import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* @Description: 方法耗时计算类
* @author: wanjun
*/
public class TimeCostUtil implements AutoCloseable
{
private static final Logger LOGGER = LoggerFactory.getLogger(TimeCostUtil.class);
/** 执行开始时间 */
private long start;
/** 执行位置 */
private String local;
public TimeCostUtil()
{
this.start = System.currentTimeMillis();
}
public TimeCostUtil(String local)
{
this.start = System.currentTimeMillis();
this.local = local;
}
@Override
public void close()
{
LOGGER.info(local + "执行耗时: " + (System.currentTimeMillis() - start));
}
}
使用如下:
try(TimeCostUtil timeCost = new TimeCostUtil("获取列表接口"))
{
}catch{
}