本文整理汇总了Java中java.util.concurrent.TimeUnit.toMillis方法的典型用法代码示例。如果您正苦于以下问题:Java TimeUnit.toMillis方法的具体用法?Java TimeUnit.toMillis怎么用?Java TimeUnit.toMillis使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.util.concurrent.TimeUnit
的用法示例。
在下文中一共展示了TimeUnit.toMillis方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: closeIdle
import java.util.concurrent.TimeUnit; //导入方法依赖的package包/类
/**
* Closes connections that have been idle longer than the given period
* of time and evicts them from the pool.
*
* @param idletime maximum idle time.
* @param tunit time unit.
*/
public void closeIdle(final long idletime, final TimeUnit tunit) {
Args.notNull(tunit, "Time unit");
long time = tunit.toMillis(idletime);
if (time < 0) {
time = 0;
}
final long deadline = System.currentTimeMillis() - time;
enumAvailable(new PoolEntryCallback<T, C>() {
@Override
public void process(final PoolEntry<T, C> entry) {
if (entry.getUpdated() <= deadline) {
entry.close();
}
}
});
}
示例2: get
import java.util.concurrent.TimeUnit; //导入方法依赖的package包/类
public synchronized T get(final long timeout, final TimeUnit unit)
throws InterruptedException, ExecutionException, TimeoutException {
Args.notNull(unit, "Time unit");
final long msecs = unit.toMillis(timeout);
final long startTime = (msecs <= 0) ? 0 : System.currentTimeMillis();
long waitTime = msecs;
if (this.completed) {
return getResult();
} else if (waitTime <= 0) {
throw new TimeoutException();
} else {
for (;;) {
wait(waitTime);
if (this.completed) {
return getResult();
} else {
waitTime = msecs - (System.currentTimeMillis() - startTime);
if (waitTime <= 0) {
throw new TimeoutException();
}
}
}
}
}
示例3: awaitTermination
import java.util.concurrent.TimeUnit; //导入方法依赖的package包/类
/**
* {@inheritDoc}
*/
@Override
public boolean awaitTermination(long timeout, TimeUnit unit) throws InterruptedException {
long deadline = System.currentTimeMillis() + unit.toMillis(timeout);
synchronized (workers) {
while (!isTerminated()) {
long waitTime = deadline - System.currentTimeMillis();
if (waitTime <= 0) {
break;
}
workers.wait(waitTime);
}
}
return isTerminated();
}
示例4: Request
import java.util.concurrent.TimeUnit; //导入方法依赖的package包/类
public Request(Object id, Object message, boolean useResponseQueue, long timeout, TimeUnit unit) {
if (id == null) {
throw new IllegalArgumentException("id");
}
if (message == null) {
throw new IllegalArgumentException("message");
}
if (timeout < 0) {
throw new IllegalArgumentException("timeout: " + timeout + " (expected: 0+)");
} else if (timeout == 0) {
timeout = Long.MAX_VALUE;
}
if (unit == null) {
throw new IllegalArgumentException("unit");
}
this.id = id;
this.message = message;
this.responses = useResponseQueue ? new LinkedBlockingQueue<Object>() : null;
this.timeoutMillis = unit.toMillis(timeout);
}
示例5: scheduleWithFixedDelayAsync
import java.util.concurrent.TimeUnit; //导入方法依赖的package包/类
@Override
public RScheduledFuture<?> scheduleWithFixedDelayAsync(Runnable task, long initialDelay, long delay, TimeUnit unit) {
check(task);
byte[] classBody = getClassBody(task);
byte[] state = encode(task);
long startTime = System.currentTimeMillis() + unit.toMillis(initialDelay);
RemotePromise<Void> result = (RemotePromise<Void>) asyncScheduledServiceAtFixed.scheduleWithFixedDelay(task.getClass().getName(), classBody, state, startTime, unit.toMillis(delay));
addListener(result);
return new RedissonScheduledFuture<Void>(result, startTime);
}
示例6: schedule
import java.util.concurrent.TimeUnit; //导入方法依赖的package包/类
@Override
public AutoDisposable schedule(Runnable task, long delay, TimeUnit unit) {
if (!closed) {
TrampolineTask tt = new TrampolineTask(task, unit.toMillis(delay));
queue.offer(tt);
drain();
return tt;
}
return REJECTED;
}
示例7: addResponseSocketOpenTimeUrlParameter
import java.util.concurrent.TimeUnit; //导入方法依赖的package包/类
private void addResponseSocketOpenTimeUrlParameter(SessionStatusRequest request, UriBuilder uriBuilder) {
if (request.isResponseSocketOpenTimeSet()) {
TimeUnit timeUnit = request.getResponseSocketOpenTimeUnit();
long timeValue = request.getResponseSocketOpenTimeValue();
long queryTimeoutInMilliseconds = timeUnit.toMillis(timeValue);
uriBuilder.queryParam("timeoutMs", queryTimeoutInMilliseconds);
}
}
示例8: setTimeout
import java.util.concurrent.TimeUnit; //导入方法依赖的package包/类
@Override
public void setTimeout(long timeout, TimeUnit unit) {
if (sseReader != null) {
sseReader.setTimeout(timeout, unit);
}
readTimeoutMillis = unit.toMillis(timeout);
}
示例9: checkTimeoutArgument
import java.util.concurrent.TimeUnit; //导入方法依赖的package包/类
private long checkTimeoutArgument(long timeout, TimeUnit unit) {
if (timeout < 0) throw new IllegalArgumentException("timeout < 0");
if (unit == null) throw new NullPointerException("unit == null");
long millis = unit.toMillis(timeout);
if (millis > Integer.MAX_VALUE)
throw new IllegalArgumentException("Timeout too large.");
if (millis == 0 && timeout > 0)
throw new IllegalArgumentException("Timeout too small.");
return millis;
}
示例10: getMessages
import java.util.concurrent.TimeUnit; //导入方法依赖的package包/类
/**
* Polls the messages list for it to grow to a given minimum size at most timeout timeUnits and return a copy of
* what we have so far.
*/
public List<String> getMessages(final int minSize, final long timeout, final TimeUnit timeUnit) throws InterruptedException {
final long endMillis = System.currentTimeMillis() + timeUnit.toMillis(timeout);
while (messages.size() < minSize && System.currentTimeMillis() < endMillis) {
Thread.sleep(100);
}
return Collections.unmodifiableList(messages);
}
示例11: Cached
import java.util.concurrent.TimeUnit; //导入方法依赖的package包/类
public Cached(long cacheFor, TimeUnit timeUnit){
this.cacheForMs = timeUnit.toMillis(cacheFor);
}
示例12: readTimeout
import java.util.concurrent.TimeUnit; //导入方法依赖的package包/类
public OkHttpResource readTimeout(long timeout, TimeUnit unit) {
this.readTimeout = unit.toMillis(timeout);
hasPerRequestReadTimeout = true;
return this;
}
示例13: schedule
import java.util.concurrent.TimeUnit; //导入方法依赖的package包/类
public Subscription schedule(Action0 action, long delayTime, TimeUnit unit) {
long execTime = now() + unit.toMillis(delayTime);
return enqueue(new SleepingAction(action, this, execTime), execTime);
}
示例14: setAutoFlush
import java.util.concurrent.TimeUnit; //导入方法依赖的package包/类
/**
* Automatically flush when putting or invalidating if it's been more than
* the given time period.
*/
public synchronized void setAutoFlush(long duration, TimeUnit unit)
{
autoFlushDuration = unit.toMillis(duration);
}
示例15: createWithTimeAndSize
import java.util.concurrent.TimeUnit; //导入方法依赖的package包/类
public static <T> ReplaySubject<T> createWithTimeAndSize(long time, TimeUnit unit, int size, Scheduler scheduler) {
BoundedState<T> state = new BoundedState(new PairEvictionPolicy(new SizeEvictionPolicy(size), new TimeEvictionPolicy(unit.toMillis(time), scheduler)), new AddTimestamped(scheduler), new RemoveTimestamped());
return createWithState(state, new TimedOnAdd(state, scheduler));
}