当前位置: 首页>>代码示例>>Java>>正文


Java TimeUnit.toMillis方法代码示例

本文整理汇总了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();
            }
        }

    });
}
 
开发者ID:gusavila92,项目名称:java-android-websocket-client,代码行数:26,代码来源:AbstractConnPool.java

示例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();
                }
            }
        }
    }
}
 
开发者ID:mozilla-mobile,项目名称:FirefoxData-android,代码行数:25,代码来源:BasicFuture.java

示例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();
}
 
开发者ID:juebanlin,项目名称:util4j,代码行数:21,代码来源:FixedThreadPoolQueuesExecutor.java

示例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);
}
 
开发者ID:eclipse,项目名称:neoscada,代码行数:23,代码来源:Request.java

示例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);
}
 
开发者ID:qq1588518,项目名称:JRediClients,代码行数:11,代码来源:RedissonExecutorService.java

示例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;
}
 
开发者ID:akarnokd,项目名称:Reactive4JavaFlow,代码行数:11,代码来源:TrampolineSchedulerService.java

示例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);
  }
}
 
开发者ID:SK-EID,项目名称:smart-id-java-client,代码行数:9,代码来源:SmartIdRestConnector.java

示例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);
}
 
开发者ID:heremaps,项目名称:oksse,代码行数:8,代码来源:RealServerSentEvent.java

示例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;
}
 
开发者ID:4pp,项目名称:downloader,代码行数:11,代码来源:Config.java

示例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);
}
 
开发者ID:savantly-net,项目名称:log4j2-extended-jsonlayout,代码行数:12,代码来源:ListAppender.java

示例11: Cached

import java.util.concurrent.TimeUnit; //导入方法依赖的package包/类
public Cached(long cacheFor, TimeUnit timeUnit){
	this.cacheForMs = timeUnit.toMillis(cacheFor);
}
 
开发者ID:hotpads,项目名称:datarouter,代码行数:4,代码来源:Cached.java

示例12: readTimeout

import java.util.concurrent.TimeUnit; //导入方法依赖的package包/类
public OkHttpResource readTimeout(long timeout, TimeUnit unit) {
  this.readTimeout = unit.toMillis(timeout);
  hasPerRequestReadTimeout = true;
  return this;
}
 
开发者ID:dehora,项目名称:outland,代码行数:6,代码来源:OkHttpResource.java

示例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);
}
 
开发者ID:JackChan1999,项目名称:boohee_v5.6,代码行数:5,代码来源:TrampolineScheduler.java

示例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);
}
 
开发者ID:equella,项目名称:Equella,代码行数:9,代码来源:BatchedCache.java

示例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));
}
 
开发者ID:JackChan1999,项目名称:boohee_v5.6,代码行数:5,代码来源:ReplaySubject.java


注:本文中的java.util.concurrent.TimeUnit.toMillis方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。