定时器和启动加载器

115 阅读1分钟

定时器StopWatch

//计时器的使用
StopWatch stopWatch = new StopWatch();
stopWatch.start("task1");
Thread.sleep(2000L);
stopWatch.stop();
stopWatch.start("task2");
Thread.sleep(3000L);
stopWatch.stop();
stopWatch.start("task3");
Thread.sleep(4000L);
stopWatch.stop();
System.out.println(stopWatch.prettyPrint());

输出结果


---------------------------------------------
ns         %     Task name
---------------------------------------------
1999189373  022%  task1
2999812276  033%  task2
3999678139  044%  task3

启动加载器

两种实现方式分别是实现ApplicationRunner接口和CommandLineRunner接口,重写run方法即可,多个启动加载器通过order值指定顺序,但是如果order值相同的话ApplicationRunner的实现会优先执行。