深圳燃气公司有哪些,深圳seo论坛,让做网站策划没经验怎么办,学徒制下的课程网站建设StopWath是 apache commons lang3 包下的一个任务执行时间监视器#xff0c;与我们平时常用的秒表的行为比较类似#xff0c;我们先看一下其中的一些重要方法#xff1a; !-- https://mvnrepository.com/artifact/org.apache.commons/commons-lang3 --
dependen…StopWath是 apache commons lang3 包下的一个任务执行时间监视器与我们平时常用的秒表的行为比较类似我们先看一下其中的一些重要方法 !-- https://mvnrepository.com/artifact/org.apache.commons/commons-lang3 --
dependency groupIdorg.apache.commons/groupId artifactIdcommons-lang3/artifactId version3.6/version
/dependency
Apache提供的这个任务执行监视器功能丰富强大灵活性强如下经典实用案例
public static void main(String[] args) throws InterruptedException { //创建后立即start常用 StopWatch watch StopWatch.createStarted();// StopWatch watch new StopWatch(); // watch.start(); Thread.sleep(1000); System.out.println(watch.getTime()); System.out.println(统计从开始到现在运行时间 watch.getTime() ms);Thread.sleep(1000); watch.split(); System.out.println(从start到此刻为止的时间 watch.getTime()); System.out.println(从开始到第一个切入点运行时间 watch.getSplitTime());Thread.sleep(1000); watch.split(); System.out.println(从开始到第二个切入点运行时间 watch.getSplitTime()); // 复位后, 重新计时 watch.reset(); watch.start(); Thread.sleep(1000); System.out.println(重新开始后到当前运行时间是 watch.getTime()); // 暂停 与 恢复 watch.suspend(); System.out.println(暂停2秒钟); Thread.sleep(2000); // 上面suspend这里要想重新统计需要恢复一下 watch.resume(); System.out.println(恢复后执行的时间是 watch.getTime());Thread.sleep(1000); watch.stop();System.out.println(花费的时间》》 watch.getTime() ms); // 直接转成s System.out.println(花费的时间》》 watch.getTime(TimeUnit.SECONDS) s);
}