StopWatch 是 apache commons lang3 包下的一个任务执行时间监视器类
需求场景:记录代码执行时间,分析耗时瓶颈
主要方法:
start(); //开始计时
split(); // 设置 split 点
getSplitTime(); // 获取从 start 到最后一次 split 的时间
reset(); //重置计时
suspend(); //暂停计时
resume(); // 恢复计时
stop(); // 停止计时
getTime(); // 统计从 start 到现在的计时
代码清单:
/**
* Created with IDEA
* author:Dingsheng Huang
* Date:2019/4/4
* Time:下午4:32
*/
public class StopWatchDemo {
public static void main (String[] args) throws InterruptedException {
StopWatch stopWatch = new StopWatch();
// 计时开始点
stopWatch.start();
// do something ...
Thread.sleep(1000);
// 断点1
stopWa