java.lang.Thread.parkUntil()方法的使用及代码示例

x33g5p2x  于2022-01-16 转载在 其他  
字(6.6k)|赞(0)|评价(0)|浏览(233)

本文整理了Java中java.lang.Thread.parkUntil()方法的一些代码示例,展示了Thread.parkUntil()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Thread.parkUntil()方法的具体详情如下:
包路径:java.lang.Thread
类名称:Thread
方法名:parkUntil

Thread.parkUntil介绍

[英]Parks the current thread until the specified system time. This method attempts to unpark the current thread immediately after System.currentTimeMillis() reaches the specified value, if no other thread unparks it first. If the thread has been "preemptively unparked," this method cancels that unparking and returns immediately. This method may also return spuriously (that is, without the thread being told to unpark and without the indicated amount of time elapsing).

See java.util.concurrent.locks.LockSupport for more in-depth information of the behavior of this method.

This method must only be called when this is the current thread.
[中]将当前线程停驻到指定的系统时间。如果没有其他线程先对当前线程进行解列,则此方法会在System.currentTimeMillis()达到指定值后立即尝试对其进行解列。如果线程已被“抢占式解列”,此方法将取消该解列并立即返回。此方法也可能会错误地返回(也就是说,没有告诉线程进行unpark,也没有指定的时间)。
参见java。util。同时发生的锁。LockSupport可获取此方法行为的更深入信息。
只有当this是当前线程时,才能调用此方法。

代码示例

代码示例来源:origin: robovm/robovm

/**
 * Parks the calling thread for the specified amount of time,
 * unless the "permit" for the thread is already available (due to
 * a previous call to {@link #unpark}. This method may also return
 * spuriously (that is, without the thread being told to unpark
 * and without the indicated amount of time elapsing).
 *
 * <p>See {@link java.util.concurrent.locks.LockSupport} for more
 * in-depth information of the behavior of this method.</p>
 *
 * @param absolute whether the given time value is absolute
 * milliseconds-since-the-epoch (<code>true</code>) or relative
 * nanoseconds-from-now (<code>false</code>)
 * @param time the (absolute millis or relative nanos) time value
 */
public void park(boolean absolute, long time) {
  if (absolute) {
    Thread.currentThread().parkUntil(time);
  } else {
    Thread.currentThread().parkFor(time);
  }
}

代码示例来源:origin: ibinti/bugvm

/**
 * Parks the calling thread for the specified amount of time,
 * unless the "permit" for the thread is already available (due to
 * a previous call to {@link #unpark}. This method may also return
 * spuriously (that is, without the thread being told to unpark
 * and without the indicated amount of time elapsing).
 *
 * <p>See {@link java.util.concurrent.locks.LockSupport} for more
 * in-depth information of the behavior of this method.</p>
 *
 * @param absolute whether the given time value is absolute
 * milliseconds-since-the-epoch (<code>true</code>) or relative
 * nanoseconds-from-now (<code>false</code>)
 * @param time the (absolute millis or relative nanos) time value
 */
public void park(boolean absolute, long time) {
  if (absolute) {
    Thread.currentThread().parkUntil(time);
  } else {
    Thread.currentThread().parkFor(time);
  }
}

代码示例来源:origin: com.mobidevelop.robovm/robovm-rt

/**
 * Parks the calling thread for the specified amount of time,
 * unless the "permit" for the thread is already available (due to
 * a previous call to {@link #unpark}. This method may also return
 * spuriously (that is, without the thread being told to unpark
 * and without the indicated amount of time elapsing).
 *
 * <p>See {@link java.util.concurrent.locks.LockSupport} for more
 * in-depth information of the behavior of this method.</p>
 *
 * @param absolute whether the given time value is absolute
 * milliseconds-since-the-epoch (<code>true</code>) or relative
 * nanoseconds-from-now (<code>false</code>)
 * @param time the (absolute millis or relative nanos) time value
 */
public void park(boolean absolute, long time) {
  if (absolute) {
    Thread.currentThread().parkUntil(time);
  } else {
    Thread.currentThread().parkFor(time);
  }
}

代码示例来源:origin: MobiVM/robovm

/**
 * Parks the calling thread for the specified amount of time,
 * unless the "permit" for the thread is already available (due to
 * a previous call to {@link #unpark}. This method may also return
 * spuriously (that is, without the thread being told to unpark
 * and without the indicated amount of time elapsing).
 *
 * <p>See {@link java.util.concurrent.locks.LockSupport} for more
 * in-depth information of the behavior of this method.</p>
 *
 * @param absolute whether the given time value is absolute
 * milliseconds-since-the-epoch (<code>true</code>) or relative
 * nanoseconds-from-now (<code>false</code>)
 * @param time the (absolute millis or relative nanos) time value
 */
public void park(boolean absolute, long time) {
  if (absolute) {
    Thread.currentThread().parkUntil(time);
  } else {
    Thread.currentThread().parkFor(time);
  }
}

代码示例来源:origin: FlexoVM/flexovm

/**
 * Parks the calling thread for the specified amount of time,
 * unless the "permit" for the thread is already available (due to
 * a previous call to {@link #unpark}. This method may also return
 * spuriously (that is, without the thread being told to unpark
 * and without the indicated amount of time elapsing).
 *
 * <p>See {@link java.util.concurrent.locks.LockSupport} for more
 * in-depth information of the behavior of this method.</p>
 *
 * @param absolute whether the given time value is absolute
 * milliseconds-since-the-epoch (<code>true</code>) or relative
 * nanoseconds-from-now (<code>false</code>)
 * @param time the (absolute millis or relative nanos) time value
 */
public void park(boolean absolute, long time) {
  if (absolute) {
    Thread.currentThread().parkUntil(time);
  } else {
    Thread.currentThread().parkFor(time);
  }
}

代码示例来源:origin: com.bugvm/bugvm-rt

/**
 * Parks the calling thread for the specified amount of time,
 * unless the "permit" for the thread is already available (due to
 * a previous call to {@link #unpark}. This method may also return
 * spuriously (that is, without the thread being told to unpark
 * and without the indicated amount of time elapsing).
 *
 * <p>See {@link java.util.concurrent.locks.LockSupport} for more
 * in-depth information of the behavior of this method.</p>
 *
 * @param absolute whether the given time value is absolute
 * milliseconds-since-the-epoch (<code>true</code>) or relative
 * nanoseconds-from-now (<code>false</code>)
 * @param time the (absolute millis or relative nanos) time value
 */
public void park(boolean absolute, long time) {
  if (absolute) {
    Thread.currentThread().parkUntil(time);
  } else {
    Thread.currentThread().parkFor(time);
  }
}

代码示例来源:origin: com.gluonhq/robovm-rt

/**
 * Parks the calling thread for the specified amount of time,
 * unless the "permit" for the thread is already available (due to
 * a previous call to {@link #unpark}. This method may also return
 * spuriously (that is, without the thread being told to unpark
 * and without the indicated amount of time elapsing).
 *
 * <p>See {@link java.util.concurrent.locks.LockSupport} for more
 * in-depth information of the behavior of this method.</p>
 *
 * @param absolute whether the given time value is absolute
 * milliseconds-since-the-epoch (<code>true</code>) or relative
 * nanoseconds-from-now (<code>false</code>)
 * @param time the (absolute millis or relative nanos) time value
 */
public void park(boolean absolute, long time) {
  if (absolute) {
    Thread.currentThread().parkUntil(time);
  } else {
    Thread.currentThread().parkFor(time);
  }
}

相关文章