前言
项目启动过程中,就采用StopWatch计时器,计算项目启动过程中的耗时。
内容
使用方式
StopWatch stopWatch = new StopWatch();
stopWatch.start();
//业务处理
stopWatch.stop();
其中
start步骤
业务校验,校验任务名称是否为空
保存任务名称
记录当前系统时间
stop步骤
业务校验
计算耗时
将当前任务添加到任务列表中(可选)
任务执行数加一
情况当前任务
如果是自己设计的话,可以参考下面的设计思想
/*
* Copyright 2002-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.util;
import java.text.NumberFormat;
import java.util.LinkedList;
import java.util.List;
import org.springframework.lang.Nullable;
/**
* Simple stop watch, allowing for timing of a number of tasks,
* exposing total running time and running time for each named task.
*
* <p>Conceals use of {@code System.currentTimeMillis()}, improving the
* readability of application code and reducing the likelihood of calculation errors.
*
* <p>Note that this object is not designed to be thread-safe and does not
* use synchronization.
*
* <p>This class is normally used to verify performance during proof-of-concepts
* and in development, rather than as part of production applications.
*
* @author Rod Johnson
* &#