提示:文章写完后,目录可以自动生成,如何生成可参考右边的帮助文档
目录
提示:以下是本篇文章正文内容,下面案例可供参考
public void stopWatchTest(){
StopWatch stopWatch = new StopWatch();
stopWatch.start();
// do something
Thread.sleep(1000);
stopWatch.stop();
System.out.println(stopWatch.getTotalTimeMillis());
}
将这段代码放在AOP中,就能监控接口的执行时间了。?
public void stopWatchTest(){
StopWatch stopWatch = new StopWatch();
stopWatch.start("A");
Thread.sleep(500);
stopWatch.stop();
stopWatch.start("B");
Thread.sleep(300);
stopWatch.stop();
stopWatch.start("C");
Thread.sleep(200);
stopWatch.stop();
System.out.println(stopWatch.prettyPrint());
}
输出结果展示:
这个例子非常实用,可以对比各个方法的执行时间和效率。?
快快替换掉自己写的耗时统计,简单到有手就行!