本文整理汇总了Java中java.time.Duration.dividedBy方法的典型用法代码示例。如果您正苦于以下问题:Java Duration.dividedBy方法的具体用法?Java Duration.dividedBy怎么用?Java Duration.dividedBy使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.time.Duration
的用法示例。
在下文中一共展示了Duration.dividedBy方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: shutdown
import java.time.Duration; //导入方法依赖的package包/类
public static void shutdown(ExecutorService exec, Duration timeout){
Duration halfTimeout = timeout.dividedBy(2);
long halfTimeoutMs = timeout.toMillis();
logger.info("shutting down {}", exec);
exec.shutdown();
try{
if(!exec.awaitTermination(halfTimeoutMs, TimeUnit.MILLISECONDS)){
logger.warn("{} did not shut down after {}, interrupting", exec, halfTimeout);
exec.shutdownNow();
if(!exec.awaitTermination(halfTimeoutMs, TimeUnit.MILLISECONDS)){
logger.error("could not shut down {} after {}", exec, timeout);
}
}
}catch(InterruptedException e){
logger.warn("interrupted while waiting for {} to shut down", exec);
exec.shutdownNow();
Thread.currentThread().interrupt();
}
}
示例2: dividedBy
import java.time.Duration; //导入方法依赖的package包/类
@Test(dataProvider="DividedBy")
public void dividedBy(long seconds, int nanos, int divisor, long expectedSeconds, int expectedNanos) {
Duration t = Duration.ofSeconds(seconds, nanos);
t = t.dividedBy(divisor);
assertEquals(t.getSeconds(), expectedSeconds);
assertEquals(t.getNano(), expectedNanos);
}
示例3: getAverageDurationPerIteration
import java.time.Duration; //导入方法依赖的package包/类
public Duration getAverageDurationPerIteration(){
Duration duration = getDuration();
return duration.dividedBy(numberOfIterations);
}
示例4: dividedByZero
import java.time.Duration; //导入方法依赖的package包/类
@Test(dataProvider="DividedBy", expectedExceptions=ArithmeticException.class)
public void dividedByZero(long seconds, int nanos, int divisor, long expectedSeconds, int expectedNanos) {
Duration t = Duration.ofSeconds(seconds, nanos);
t.dividedBy(0);
fail(t + " divided by zero did not throw ArithmeticException");
}
示例5: test_dividedByDur_zero
import java.time.Duration; //导入方法依赖的package包/类
@Test(expectedExceptions=ArithmeticException.class)
public void test_dividedByDur_zero() {
Duration t = Duration.ofSeconds(1, 0);
t.dividedBy(Duration.ZERO);
}
示例6: test_dividedByDur_null
import java.time.Duration; //导入方法依赖的package包/类
@Test(expectedExceptions=NullPointerException.class)
public void test_dividedByDur_null() {
Duration t = Duration.ofSeconds(1, 0);
t.dividedBy(null);
}
示例7: test_dividedByDur_overflow
import java.time.Duration; //导入方法依赖的package包/类
@Test(expectedExceptions=ArithmeticException.class)
public void test_dividedByDur_overflow() {
Duration dur1 = Duration.ofSeconds(Long.MAX_VALUE, 0);
Duration dur2 = Duration.ofNanos(1);
dur1.dividedBy(dur2);
}