import lombok.extern.slf4j.Slf4j;
import org.springframework.util.StopWatch;
@Slf4j
public class StopWatchTest {
public static void main(String[] args) throws InterruptedException {
StopWatch stopWatch = new StopWatch("每日工作时间");
stopWatch.start("上午");
forenoon();
stopWatch.stop();
stopWatch.start("午饭");
lunch();
stopWatch.stop();
stopWatch.start("午休");
noonBreak();
stopWatch.stop();
stopWatch.start("下午");
afternoon();
stopWatch.stop();
StopWatch.TaskInfo[] taskInfos = stopWatch.getTaskInfo();
for (StopWatch.TaskInfo taskInfo : taskInfos) {
log.info("{} 花费 {}s", taskInfo.getTaskName(), taskInfo.getTimeSeconds());
}
}
private static void forenoon() throws InterruptedException {
Thread.sleep(3000);
}
private static void lunch() throws InterruptedException {
Thread.sleep(1000);
}
private static void noonBreak() throws InterruptedException {
Thread.sleep(1000);
}
private static void afternoon() throws InterruptedException {
Thread.sleep(3000);
}
}
Spring StopWatch代码示例
最新推荐文章于 2023-06-27 22:34:57 发布