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

  


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM