java TimeUnit.SECONDS与TimeUnit.MILLISECONDS区别

TimeUnit.SECONDS(5)线程等待五秒

TimeUnit.MILLISECONDS(5000)线程等待五秒.

两者的时间单位不一样。

内部都是Thread.sleep实现。

 

public static TimeUnit toTimeUnit(final HBaseProtos.TimeUnit proto) {
  switch (proto) {
  case NANOSECONDS:
    return TimeUnit.NANOSECONDS;
  case MICROSECONDS:
    return TimeUnit.MICROSECONDS;
  case MILLISECONDS:
    return TimeUnit.MILLISECONDS;
  case SECONDS:
    return TimeUnit.SECONDS;
  case MINUTES:
    return TimeUnit.MINUTES;
  case HOURS:
    return TimeUnit.HOURS;
  case DAYS:
    return TimeUnit.DAYS;
  default:
    throw new RuntimeException("Invalid TimeUnit " + proto);
  }
}

 

 

 

 

posted @ 2023-01-01 10:19  锐洋智能  阅读(963)  评论(0编辑  收藏  举报