java计时器StopWatch

 请求接口时有时需要知道请求时间,所以用到stopwatch

导入jar包

<dependency>
            <groupId>org.apache.commons</groupId>
            <artifactId>commons-lang3</artifactId>
            <version>3.3.2</version>
        </dependency>

 

public static void main(String[] args) {
    //创建并启动StopWatch
    StopWatch stopwatch = StopWatch.createStarted();
    try{
    //主体代码
    Thread.sleep(2000);
}finally{ stopwatch.stop(); }; System.out.println(stopwatch); }


 

posted @ 2020-10-10 16:19  不屈的鸣人  阅读(531)  评论(0编辑  收藏  举报