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


Java TimeUnit.timedWait方法代码示例

本文整理汇总了Java中java.util.concurrent.TimeUnit.timedWait方法的典型用法代码示例。如果您正苦于以下问题:Java TimeUnit.timedWait方法的具体用法?Java TimeUnit.timedWait怎么用?Java TimeUnit.timedWait使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.util.concurrent.TimeUnit的用法示例。


在下文中一共展示了TimeUnit.timedWait方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: get

import java.util.concurrent.TimeUnit; //导入方法依赖的package包/类
@Override
public T get(long timeout, TimeUnit unit)
    throws InterruptedException, ExecutionException, TimeoutException {
  synchronized (tasks) {
    if (resultObtained) {
      return result;
    }
    if (exeEx != null) {
      throw exeEx;
    }
    unit.timedWait(tasks, timeout);
  }
  if (resultObtained) {
    return result;
  }
  if (exeEx != null) {
    throw exeEx;
  }

  throw new TimeoutException("timeout=" + timeout + ", " + unit);
}
 
开发者ID:fengchen8086,项目名称:ditb,代码行数:22,代码来源:ResultBoundedCompletionService.java

示例2: waitOnStatusResponse

import java.util.concurrent.TimeUnit; //导入方法依赖的package包/类
/**
 * Waits for a Locator status request response to be returned up to the specified timeout in the
 * given unit of time. This call will send status requests at fixed intervals in the given unit of
 * time until the timeout expires. If the request to determine the Locator's status is successful,
 * then the Locator is considered to be 'ONLINE'. Otherwise, the Locator is considered to be
 * unresponsive to the status request.
 * 
 * However, this does not necessarily imply the Locator start was unsuccessful, only that a
 * response was not received in the given time period.
 * 
 * Note, this method does not block or cause the Locator's location-based services (daemon
 * Threads) to continue running in anyway if the main application Thread terminates when running
 * the Locator in-process. If the caller wishes to start a Locator in an asynchronous manner
 * within the application process, then a call should be made to <code>waitOnLocator</code>.
 * 
 * @param timeout a long value in time unit indicating when the period of time should expire in
 *        attempting to determine the Locator's status.
 * @param interval a long value in time unit for how frequent the requests should be sent to the
 *        Locator.
 * @param timeUnit the unit of time in which the timeout and interval are measured.
 * @return the state of the Locator, which will either be 'ONLINE' or "NOT RESPONDING'. If the
 *         status returned is 'NOT RESPONDING', it just means the Locator did not respond to the
 *         status request within the given time period. It should not be taken as the Locator
 *         failed to start.
 * @see #waitOnLocator()
 */
public LocatorState waitOnStatusResponse(final long timeout, final long interval,
    final TimeUnit timeUnit) {
  final long endTimeInMilliseconds = (System.currentTimeMillis() + timeUnit.toMillis(timeout));

  while (System.currentTimeMillis() < endTimeInMilliseconds) {
    try {
      LocatorStatusResponse response = statusLocator(getPort(), getBindAddress());
      return new LocatorState(this, Status.ONLINE, response);
    } catch (Exception ignore) {
      try {
        synchronized (this) {
          timeUnit.timedWait(this, interval);
        }
      } catch (InterruptedException ignoreInterrupt) {
        // NOTE just go and send another status request to the Locator...
      }
    }
  }

  // NOTE just because we were not able to communicate with the Locator in the given amount of
  // time does not mean
  // the Locator is having problems. The Locator could be slow in starting up and the timeout may
  // not be
  // long enough.
  return new LocatorState(this, Status.NOT_RESPONDING);
}
 
开发者ID:ampool,项目名称:monarch,代码行数:53,代码来源:LocatorLauncher.java

示例3: get

import java.util.concurrent.TimeUnit; //导入方法依赖的package包/类
@Override
public CommandResult get(long timeout, TimeUnit unit)
        throws InterruptedException, ExecutionException, TimeoutException {
    synchronized (this) {
        if (result != null) {
            return result;
        }
        unit.timedWait(this, timeout);
        if (result == null) {
            set(new CommandResult());
            networkManager.removeCommandExecution(commandExecution);
        }
        return result;
    }
}
 
开发者ID:zsmartsystems,项目名称:com.zsmartsystems.zigbee,代码行数:16,代码来源:CommandResultFuture.java

示例4: poll

import java.util.concurrent.TimeUnit; //导入方法依赖的package包/类
public QueueingFuture<V> poll(long timeout, TimeUnit unit) throws InterruptedException {
  synchronized (tasks) {
    if (completed == null && !cancelled) unit.timedWait(tasks, timeout);
  }
  return completed;
}
 
开发者ID:fengchen8086,项目名称:ditb,代码行数:7,代码来源:ResultBoundedCompletionService.java


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