spring提供了一个StopWatch类能够作相似任务执行时间计算:

package yt.gk.goodsservice.config;

import org.springframework.util.StopWatch;

public class MainTime {
    public static void main(String[] args) {
        //spring提供了一个StopWatch类能够作相似任务执行时间计算:
        StopWatch sw = new StopWatch();
        //业务开始时间
        sw.start();

       // 业务操做
        for(int i=0;i<300;i++){
            System.out.println(i);
        }

        //业务结束时间
        sw.stop();

        System.out.println("程序所耗时间为:"+sw.getTotalTimeMillis());
    }
}

程序执行结果:spring

单位时毫秒msblog

相关文章
相关标签/搜索