性能监控代码
package com.jd.app.server.test.service;
import org.springframework.util.StopWatch;
public class Test {
@org.junit.Test
public void test(){
StopWatch stopWatch = new StopWatch("方法性能测试");
try {
stopWatch.start("任务1");
Thread.sleep(1000);
stopWatch.stop();
stopWatch.start("任务2");
Thread.sleep(3000);
stopWatch.stop();
stopWatch.start("任务3");
Thread.sleep(500);
stopWatch.stop();
stopWatch.start("任务4");
Thread.sleep(2000);
stopWatch.stop();
} catch (InterruptedException e) {
e.printStackTrace();
} finally {
if (stopWatch.isRunning()) {
stopWatch.stop();
}
System.out.println(stopWatch.prettyPrint());
}
}
}
执行结果