好用的监控工具,spring StopWatch

public class TestStopWatch {
    public static void main(String[] args) {
        StopWatch stopWatch = new StopWatch("统一一组任务耗时");

// 统计任务一耗时

        stopWatch.start("任务一");

        try {
            Thread.sleep(100030);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        stopWatch.stop();

// 统计任务二耗时

        stopWatch.start("任务二");

        try {
            Thread.sleep(2000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        stopWatch.stop();

// 打印出耗时

        String result = stopWatch.prettyPrint();

        System.out.println(result);
        System.out.println("=============");
        System.out.println(stopWatch.getTotalTimeMillis());
        System.out.println(stopWatch.getLastTaskName());
        System.out.println(stopWatch.getLastTaskInfo());
        System.out.println(stopWatch.getTaskCount());
        System.out.println("=============");
        StopWatch.TaskInfo[] taskInfos = stopWatch.getTaskInfo();
        for(StopWatch.TaskInfo taskInfo:taskInfos){
            System.out.println(taskInfo.getTaskName());
            System.out.println(taskInfo.getTimeMillis());
            System.out.println(taskInfo.getTimeSeconds());
        }
    }
}

你可能感兴趣的:(java)