TimeUnit工具类

TimeUnit工具类

TimeUnit

A. 使线程暂停
相比于Thread.sleep(),TimeUnit._.sleep()可读性更高,以及...
TimeUnit.MINUTES.sleep(4);  // sleeping for 4 minutes

TimeUnit.SECONDS.sleep(4);
TimeUnit.MINUTES.sleep(4);
TimeUnit.HOURS.sleep(1);
TimeUnit.DAYS.sleep(1);


提供不同时间单位的转换
TimeUnit.SECONDS.toMillis(44)

System.out.println(timeUnit.name());
System.out.println(timeUnit.toDays(1));
System.out.println(timeUnit.toHours(1));
System.out.println(timeUnit.toMinutes(1));
System.out.println(timeUnit.toMicros(1));
System.out.println(timeUnit.toMillis(1));
System.out.println(timeUnit.toNanos(1));
System.out.println(timeUnit.toSeconds(1));

TimeUnit是并发编程中一个有用的类

标签

评论

© 2021 成都云创动力科技有限公司 蜀ICP备20006351号-1