【Apache Commons Lang】StopWatch任务执行时间监视器

StopWath是apache commons lang包下的一个任务执行时间监视器

 

package com.zjq.appacheTest;  
  
import org.apache.commons.lang3.time.StopWatch;  
  
/** 
 * start(); //开始计时 
 * split(); //设置split点 
 * getSplitTime(); //获取从start 到 最后一次split的时间 
 * reset(); //重置计时 
 * suspend(); //暂停计时, 直到调用 
 * resume()后才恢复计时  
 * resume(); //恢复计时 
 * stop(); //停止计时  
 * getTime(); //统计从start到现在的计时 
 */  
  
public class StopWatchTest {  
    public static void main(String[] args) throws InterruptedException {  
        StopWatch watch = new StopWatch();  
        watch.start();  
  
        // 统计从start开始经历的时间  
        Thread.sleep(1000);  
        System.out.println("1-"+watch.getTime());  
  
        // 统计计时点  
        Thread.sleep(1000);  
        watch.split();  
        System.out.println("2-"+watch.getSplitTime());  
  
        // 统计计时点  
        Thread.sleep(1000);  
        watch.split();  
        System.out.println("3-"+watch.getSplitTime());  
  
        // 复位后, 重新计时  
        watch.reset();  
        watch.start();  
        Thread.sleep(1000);  
        System.out.println("4-"+watch.getTime());  
  
        // 暂停 与 恢复  
        watch.suspend();  
        System.out.println("暂停2秒钟");  
        Thread.sleep(2000);  
  
        watch.resume();  
        Thread.sleep(1000);  
        watch.stop();  
        System.out.println("5-"+watch.getTime());  
    }  
  
}  

 

 

转载于:https://my.oschina.net/zjllovecode/blog/1815033

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值