SpringBoot --- StopWatch (计时器)

  StopWatch 是 org.springframework.util包下面的一个工具类,通过这个可以对程序部分代码进行计时。适用于同步单线程代码块。
  使用展示:

/**
 * Unit test for simple App.
 */
public class AppTest 
{
    public static void main(String[] args) {
    	//1,声明计时器
        StopWatch stopWatch = new StopWatch();
        stopWatch.start("测试");
         
         //2,编写代码进程
        int y = 0;
        for (int i = 0; i < 1000; i++) {
            y+=i;
        }

		//3,计时停止
        stopWatch.stop();

		//4,输出显示计时器各种数据
        System.out.println("----id: " + stopWatch.getId());
        System.out.println("----TotalTimeMillis: " + stopWatch.getTotalTimeMillis());
        System.out.println("----TotalTimeSeconds: " + stopWatch.getTotalTimeSeconds());
        System.out.println("----LastTaskName: " + stopWatch.getLastTaskName());
        System.out.println("----LastTaskInfo: " + stopWatch.getLastTaskInfo());
        System.out.println("----LastTaskTimeMillis: " + stopWatch.getLastTaskTimeMillis());
        System.out.println("----LastTaskTimeNanos: " + stopWatch.getLastTaskTimeNanos());
        System.out.println("----TaskCount: " + stopWatch.getTaskCount());
        System.out.println("----TotalTimeNanos: " + stopWatch.getTotalTimeNanos());
    }
}
输出:
"C:\Program Files (x86)\Java\jdk1.8.0_31\bin\java.exe" .........
----id: 
----TotalTimeMillis: 1
----TotalTimeSeconds: 0.0010872
----LastTaskName: 测试
----LastTaskInfo: org.springframework.util.StopWatch$TaskInfo@176f3f8
----LastTaskTimeMillis: 1
----LastTaskTimeNanos: 1087200
----TaskCount: 1
----TotalTimeNanos: 1087200

Process finished with exit code 0

你可能感兴趣的:(SpringBoot,spring,boot,java,intellij-idea)