首页 > 编程语言 > 详细

Spring Boot计时器

时间:2020-02-27 12:46:22      阅读:219      评论:0      收藏:0      [点我收藏+]

Sping Boot计时器

用来统计任务的耗时

 

1、进入run方法,其中StopWatch就是计时器

技术分享图片

 

2、计时器的使用

@RunWith(SpringRunner.class)
@SpringBootTest
public class StopWatchTest {
    
    @Test
    public void testStopWatch() throws InterruptedException {
        StopWatch myWatch = new StopWatch("myWatch");
        myWatch.start("task1");
        Thread.sleep(2000L);
        myWatch.stop();

        myWatch.start("task2");
        Thread.sleep(3000L);
        myWatch.stop();

        myWatch.start("task3");
        Thread.sleep(1000L);
        myWatch.stop();

        System.out.println( myWatch.prettyPrint());


    }



}

  

运行testStopWatch方法,输出结果如下

StopWatch ‘myWatch‘: running time (millis) = 6003
-----------------------------------------
ms     %     Task name
-----------------------------------------
02000  033%  task1
03002  050%  task2
01001  017%  task3

  

Spring Boot计时器

原文:https://www.cnblogs.com/linlf03/p/12371134.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!