zoukankan      html  css  js  c++  java
  • Spring Boot计时器

    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
    

      

  • 相关阅读:
    第二周学习总结
    2019春总结作业
    第十二周作业
    第十一周作业
    第九周作业
    第八周作业
    第七周作业
    第六周作业
    第五周课程总结与报告
    Java第四周编程总结
  • 原文地址:https://www.cnblogs.com/linlf03/p/12371134.html
Copyright © 2011-2022 走看看