|
|
@ -1,18 +1,18 @@
|
|
|
|
# Spring StopWatch
|
|
|
|
# Spring StopWatch
|
|
|
|
- Author: [HuiFer](https://github.com/huifer)
|
|
|
|
- Author: [HuiFer](https://github.com/huifer)
|
|
|
|
- 源码阅读仓库: [SourceHot-spring](https://github.com/SourceHot/spring-framework-read)
|
|
|
|
- 源码阅读仓库: [SourceHot-spring](https://github.com/SourceHot/spring-framework-read)
|
|
|
|
|
|
|
|
|
|
|
|
- 全路径: `org.springframework.util.StopWatch`
|
|
|
|
- 全路径: `org.springframework.util.StopWatch`
|
|
|
|
## 属性
|
|
|
|
## 属性
|
|
|
|
- taskList: 任务信息列表
|
|
|
|
- taskList: 任务信息列表
|
|
|
|
- keepTaskList: 是否保留任务信息列表
|
|
|
|
- keepTaskList: 是否保留任务信息列表
|
|
|
|
- startTimeMillis: 任务开始的时间
|
|
|
|
- startTimeMillis: 任务开始的时间
|
|
|
|
- currentTaskName: 任务名称
|
|
|
|
- currentTaskName: 任务名称
|
|
|
|
- lastTaskInfo: 任务信息
|
|
|
|
- lastTaskInfo: 任务信息
|
|
|
|
- taskCount: 任务数量
|
|
|
|
- taskCount: 任务数量
|
|
|
|
- totalTimeMillis: 总共花费的时间
|
|
|
|
- totalTimeMillis: 总共花费的时间
|
|
|
|
|
|
|
|
|
|
|
|
## 方法
|
|
|
|
## 方法
|
|
|
|
- `org.springframework.util.StopWatch.start(java.lang.String)`
|
|
|
|
- `org.springframework.util.StopWatch.start(java.lang.String)`
|
|
|
|
```java
|
|
|
|
```java
|
|
|
|
public void start(String taskName) throws IllegalStateException {
|
|
|
|
public void start(String taskName) throws IllegalStateException {
|
|
|
@ -29,10 +29,10 @@
|
|
|
|
if (this.currentTaskName == null) {
|
|
|
|
if (this.currentTaskName == null) {
|
|
|
|
throw new IllegalStateException("Can't stop StopWatch: it's not running");
|
|
|
|
throw new IllegalStateException("Can't stop StopWatch: it's not running");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// 消费的时间
|
|
|
|
// 消费的时间
|
|
|
|
long lastTime = System.currentTimeMillis() - this.startTimeMillis;
|
|
|
|
long lastTime = System.currentTimeMillis() - this.startTimeMillis;
|
|
|
|
this.totalTimeMillis += lastTime;
|
|
|
|
this.totalTimeMillis += lastTime;
|
|
|
|
// 任务信息初始化
|
|
|
|
// 任务信息初始化
|
|
|
|
this.lastTaskInfo = new TaskInfo(this.currentTaskName, lastTime);
|
|
|
|
this.lastTaskInfo = new TaskInfo(this.currentTaskName, lastTime);
|
|
|
|
if (this.keepTaskList) {
|
|
|
|
if (this.keepTaskList) {
|
|
|
|
this.taskList.add(this.lastTaskInfo);
|
|
|
|
this.taskList.add(this.lastTaskInfo);
|
|
|
|