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

来源:互联网 发布:cad2016简体中文版mac 编辑:程序博客网 时间:2024/05/22 14:17
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());}}
原文链接:【Apache Commons Lang】StopWatch任务执行时间监视器