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

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

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

Thread.parkFor介绍

[英]Parks the current thread for a particular number of nanoseconds, or indefinitely. If not indefinitely, this method unparks the thread after the given number of nanoseconds 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.
[中]将当前线程停止特定的纳秒数,或无限期地停止。如果不是无限期的,如果没有其他线程先解压线程,则此方法将在给定的纳秒数后解压线程。如果线程已被“抢占式解列”,此方法将取消该解列并立即返回。此方法也可能会错误地返回(也就是说,没有告诉线程进行unpark,也没有指定的时间)。
参见java。util。同时发生的锁。LockSupport可获取此方法行为的更深入信息。
只有当this是当前线程时,才能调用此方法。

代码示例

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

parkState = ParkState.UNPARKED;
} else {
  parkFor(delayMillis * NANOS_PER_MILLI);

代码示例来源: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: FlexoVM/flexovm

parkState = ParkState.UNPARKED;
} else {
  parkFor(delayMillis * NANOS_PER_MILLI);

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

parkState = ParkState.UNPARKED;
} else {
  parkFor(delayMillis * NANOS_PER_MILLI);

代码示例来源: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: MobiVM/robovm

parkState = ParkState.UNPARKED;
} else {
  parkFor(delayMillis * NANOS_PER_MILLI);

代码示例来源: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: com.mobidevelop.robovm/robovm-rt

parkState = ParkState.UNPARKED;
} else {
  parkFor(delayMillis * NANOS_PER_MILLI);

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

parkState = ParkState.UNPARKED;
} else {
  parkFor(delayMillis * NANOS_PER_MILLI);

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

parkState = ParkState.UNPARKED;
} else {
  parkFor(delayMillis * NANOS_PER_MILLI);

代码示例来源: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);
  }
}

代码示例来源: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: 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);
  }
}

相关文章