本文整理汇总了Java中java.util.concurrent.TimeUnit.name方法的典型用法代码示例。如果您正苦于以下问题:Java TimeUnit.name方法的具体用法?Java TimeUnit.name怎么用?Java TimeUnit.name使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.util.concurrent.TimeUnit
的用法示例。
在下文中一共展示了TimeUnit.name方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: abbreviate
import java.util.concurrent.TimeUnit; //导入方法依赖的package包/类
private static String abbreviate(TimeUnit unit) {
switch (unit) {
case NANOSECONDS:
return "ns";
case MICROSECONDS:
return "μs";
case MILLISECONDS:
return "ms";
case SECONDS:
return "s";
case MINUTES:
return "min";
case HOURS:
return "h";
case DAYS:
return "d";
default:
throw new RuntimeException("Unsupported unit " + unit.name());
}
}
示例2: set
import java.util.concurrent.TimeUnit; //导入方法依赖的package包/类
/**
* Set the RateLimiter max available resources and refill period.
* @param limit The max value available resource units can be refilled to.
* @param timeUnit Timeunit factor for translating to ms.
*/
public synchronized void set(final long limit, final TimeUnit timeUnit) {
switch (timeUnit) {
case MILLISECONDS:
tunit = 1;
break;
case SECONDS:
tunit = 1000;
break;
case MINUTES:
tunit = 60 * 1000;
break;
case HOURS:
tunit = 60 * 60 * 1000;
break;
case DAYS:
tunit = 24 * 60 * 60 * 1000;
break;
default:
throw new RuntimeException("Unsupported " + timeUnit.name() + " TimeUnit.");
}
this.limit = limit;
this.avail = limit;
}