File tree 1 file changed +44
-0
lines changed
1 file changed +44
-0
lines changed Original file line number Diff line number Diff line change
1
+ # Spring StopWatch
2
+ - Author: [ HuiFer] ( https://github.com/huifer )
3
+ - 源码阅读仓库: [ SourceHot-spring] ( https://github.com/SourceHot/spring-framework-read )
4
+
5
+ - 全路径: ` org.springframework.util.StopWatch `
6
+ ## 属性
7
+ - taskList: 任务信息列表
8
+ - keepTaskList: 是否保留任务信息列表
9
+ - startTimeMillis: 任务开始的时间
10
+ - currentTaskName: 任务名称
11
+ - lastTaskInfo: 任务信息
12
+ - taskCount: 任务数量
13
+ - totalTimeMillis: 总共花费的时间
14
+
15
+ ## 方法
16
+ - ` org.springframework.util.StopWatch.start(java.lang.String) `
17
+ ``` java
18
+ public void start(String taskName) throws IllegalStateException {
19
+ if (this . currentTaskName != null ) {
20
+ throw new IllegalStateException (" Can't start StopWatch: it's already running" );
21
+ }
22
+ this . currentTaskName = taskName;
23
+ this . startTimeMillis = System . currentTimeMillis();
24
+ }
25
+ ```
26
+ - ` org.springframework.util.StopWatch.stop `
27
+ ``` java
28
+ public void stop() throws IllegalStateException {
29
+ if (this . currentTaskName == null ) {
30
+ throw new IllegalStateException (" Can't stop StopWatch: it's not running" );
31
+ }
32
+ // 消费的时间
33
+ long lastTime = System . currentTimeMillis() - this . startTimeMillis;
34
+ this . totalTimeMillis += lastTime;
35
+ // 任务信息初始化
36
+ this . lastTaskInfo = new TaskInfo (this . currentTaskName, lastTime);
37
+ if (this . keepTaskList) {
38
+ this . taskList. add(this . lastTaskInfo);
39
+ }
40
+ ++ this . taskCount;
41
+ this . currentTaskName = null ;
42
+ }
43
+
44
+ ```
You can’t perform that action at this time.
0 commit comments