StopWatch from springframework

## Test code
```java
public static void main(String[] args) throws InterruptedException {
StopWatch stopWatch = new StopWatch("StopWatchOfGYYX");

System.out.println("******A timer task starts* *****");
stopWatch.start("A logical time test");
Thread.sleep(1002);
System.out.println("Whether it is running: " + stopWatch.isRunning());
stopWatch.stop ();
System.out.println("Time in this stage:" + stopWatch.getLastTaskTimeMillis());
System.out.println("stopWatch total time (mil):" + stopWatch.getTotalTimeMillis());
System. out.println("stopWatch total time (sec):" + stopWatch.getTotalTimeSeconds());
System.out.println("last task name:" + stopWatch.getLastTaskInfo().getTaskName());
System.out.println("Last task time (mil):" + stopWatch.getLastTaskInfo().getTimeMillis());
System.out.println("Last task time (sec):" + stopWatch.getLastTaskInfo ().getTimeSeconds());
System.out.println("");
System.out.println("************************ **************************************************** *************");

System.out.println("******B timing task start******");
stopWatch.start("B logical time Test");
Thread.sleep(1008);
stopWatch.stop();
System.out.println("Whether it is running: " + stopWatch.isRunning());
System.out.println("This stage takes time:" + stopWatch.getLastTaskTimeMillis());
System.out.println("stopWatch total time (mil):" + stopWatch.getTotalTimeMillis());
System.out.println("stopWatch total time (sec):" + stopWatch.getTotalTimeSeconds());
System.out.println("last task name:" + stopWatch.getLastTaskInfo().getTaskName());
System .out.println("Last task time (mil):" + stopWatch.getLastTaskInfo().getTimeMillis());
System.out.println("Last task time (sec):" + stopWatch.getLastTaskInfo( ).getTimeSeconds());
System.out.println("");
System.out.println("************************** **************************************************** ************");

System.out.println("******C timing task start******");
stopWatch.start();//" c Logical time test"
Thread.sleep(1006);
stopWatch.stop();
System.out.println("This stage takes time: " + stopWatch. getLastTaskTimeMillis());
System.out.println("stopWatch total time (mil):" + stopWatch.getTotalTimeMillis());
System.out.println("stopWatch total time (sec):" + stopWatch.getTotalTimeSeconds());
System. out.println("The last task name: " + stopWatch.getLastTaskInfo().getTaskName());
System.out.println("The last task time (mil): " + stopWatch.getLastTaskInfo().getTimeMillis() );
System.out.println("Last task time (sec): " + stopWatch.getLastTaskInfo().getTimeSeconds());
System.out.println("");
System.out.println("** **************************************************** ************************************");

System.out.println("**** ***Summary information*******");
System.out.println("Total number of tasks: " + stopWatch.getTaskCount());
System.out. println("Total task time (mil): " + stopWatch.getTotalTimeMillis());
System.out.println("Total task time (sec):" + stopWatch.getTotalTimeSeconds());
System.out.println("Total task brief:" + stopWatch.shortSummary());
System.out.println( "");

System.out.println("**************************************** ****************************************************" );
System.out.println("*******task list traversal*******");
TaskInfo[] taskInfo = stopWatch.getTaskInfo();
for (int i = 0; i < taskInfo .length; i++) {
System.out.println("Total task list [" + i + "] name:" + taskInfo[i].getTaskName());
System.out.println("Total task list [" + i + "] time-consuming mil:" + taskInfo[i].getTimeMillis());
System.out.println("Total task list [" + i + "] time-consuming sec:" + taskInfo[i].getTimeSeconds( ));

}


System.out.println("******************************************** ********************************************");
System. out.println("******formatted display ********");
System.out.println(stopWatch.prettyPrint());
}
```

## Execution result

```txt
******A timing task starts******
Whether it is running: true Time
spent in this stage: 1003
Total stopWatch time (mil): 1003
Total stopWatch time (sec): 1.003
Last task name: A logic time test
Last task time (mil): 1003
Last task time (sec): 1.003

************************** **************************************************** ************
******B timing task starts ******
Whether it is running: false Time
spent in this stage: 1008
Total stopWatch time (mil): 2011
StopWatch total Time (sec): 2.011
Last task name: B logic time test
Last task time (mil): 1008
Last task time (sec): 1.008

********************* **************************************************** ****************
******C timing task starts ****** Time
spent in this stage: 1007
total stopWatch time (mil): 3018
stopWatch total Time (sec): 3.018
Last task name:
Last task time (mil): 1007
Last task time (sec): 1.007

****************** **************************************************** ********************
*******Summary information*******
Total number of tasks: 3Total
task time (mil): 3018
Total task time (sec): 3.018
Total task brief: StopWatch 'StopWatchOfGYYX': running time (millis) = 3018

************************ **************************************************** ****************
******Task list traversal*******
Total task list[0]Name:A logic time
testTotal task list[0] time consuming mil:1003Total
task list[0] time consuming sec: 1.003
Total Task List [1] Name: B Logical Time Test
Total Task List [1] Time Consumption mil: 1008
Total Task List [1] Time Consumption sec: 1.008
Total Task List [2] Name:
Total Task List [2] Consumption Time mil: 1007
Total task list [2] Time consuming sec: 1.007
************************************ **************************************************** ***
******formatted display********
StopWatch 'StopWatchOfGYYX': running time (millis) = 3018
------------------ -----------------------
ms % Task name
----------------------- ------------------
01003 033% A logic time test
01008 033% B logic time test
01007 033% 

```

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=327072545&siteId=291194637