SpringBoot系列---【StopWatch优雅实现统计代码耗时】

StopWatch优雅实现统计代码耗时

#org.springframework.util.StopWatch
StopWatch stopWatch = new StopWatch();
stopWatch.start("task1");
//逻辑代码1
...
stopWatch.stop();
log.debug("task1执行耗时:{}ms",stopWatch.getLastTaskTimeMillis());
stopWatch.start("task2");
//逻辑代码2
...
stopWatch.stop();
log.debug("task2执行耗时:{}ms",stopWatch.getLastTaskTimeMillis());
log.debug("总执行耗时:{}ms",stopWatch.getTotalTimeMillis());

你可能感兴趣的:(spring,boot,java,数据库,后端,spring)