java.util.concurrent.ThreadPoolExecutor.workerCountOf()方法的使用及代码示例

x33g5p2x  于2022-01-29 转载在 其他  
字(7.0k)|赞(0)|评价(0)|浏览(88)

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

ThreadPoolExecutor.workerCountOf介绍

暂无

代码示例

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

/**
 * Starts a core thread, causing it to idly wait for work. This
 * overrides the default policy of starting core threads only when
 * new tasks are executed. This method will return {@code false}
 * if all core threads have already been started.
 *
 * @return {@code true} if a thread was started
 */
public boolean prestartCoreThread() {
  return workerCountOf(ctl.get()) < corePoolSize &&
    addWorker(null, true);
}

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

/**
 * Sets the maximum allowed number of threads. This overrides any
 * value set in the constructor. If the new value is smaller than
 * the current value, excess existing threads will be
 * terminated when they next become idle.
 *
 * @param maximumPoolSize the new maximum
 * @throws IllegalArgumentException if the new maximum is
 *         less than or equal to zero, or
 *         less than the {@linkplain #getCorePoolSize core pool size}
 * @see #getMaximumPoolSize
 */
public void setMaximumPoolSize(int maximumPoolSize) {
  if (maximumPoolSize <= 0 || maximumPoolSize < corePoolSize)
    throw new IllegalArgumentException();
  this.maximumPoolSize = maximumPoolSize;
  if (workerCountOf(ctl.get()) > maximumPoolSize)
    interruptIdleWorkers();
}

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

/**
 * Same as prestartCoreThread except arranges that at least one
 * thread is started even if corePoolSize is 0.
 */
void ensurePrestart() {
  int wc = workerCountOf(ctl.get());
  if (wc < corePoolSize)
    addWorker(null, true);
  else if (wc == 0)
    addWorker(null, false);
}

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

/**
 * Transitions runState to given target, or leaves it alone if
 * already at least the given target.
 *
 * @param targetState the desired state, either SHUTDOWN or STOP
 *        (but not TIDYING or TERMINATED -- use tryTerminate for that)
 */
private void advanceRunState(int targetState) {
  for (;;) {
    int c = ctl.get();
    if (runStateAtLeast(c, targetState) ||
      ctl.compareAndSet(c, ctlOf(targetState, workerCountOf(c))))
      break;
  }
}

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

/**
 * Sets the core number of threads.  This overrides any value set
 * in the constructor.  If the new value is smaller than the
 * current value, excess existing threads will be terminated when
 * they next become idle.  If larger, new threads will, if needed,
 * be started to execute any queued tasks.
 *
 * @param corePoolSize the new core size
 * @throws IllegalArgumentException if {@code corePoolSize < 0}
 * @see #getCorePoolSize
 */
public void setCorePoolSize(int corePoolSize) {
  if (corePoolSize < 0)
    throw new IllegalArgumentException();
  int delta = corePoolSize - this.corePoolSize;
  this.corePoolSize = corePoolSize;
  if (workerCountOf(ctl.get()) > corePoolSize)
    interruptIdleWorkers();
  else if (delta > 0) {
    // We don't really know how many new threads are "needed".
    // As a heuristic, prestart enough new workers (up to new
    // core size) to handle the current number of tasks in
    // queue, but stop if queue becomes empty while doing so.
    int k = Math.min(delta, workQueue.size());
    while (k-- > 0 && addWorker(null, true)) {
      if (workQueue.isEmpty())
        break;
    }
  }
}

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

int wc = workerCountOf(c);

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

if (min == 0 && ! workQueue.isEmpty())
  min = 1;
if (workerCountOf(c) >= min)
  return; // replacement not needed

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

(runStateOf(c) == SHUTDOWN && ! workQueue.isEmpty()))
  return;
if (workerCountOf(c) != 0) { // Eligible to terminate
  interruptIdleWorkers(ONLY_ONE);
  return;

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

if (workerCountOf(c) < corePoolSize) {
  if (addWorker(command, true))
    return;
  if (! isRunning(recheck) && remove(command))
    reject(command);
  else if (workerCountOf(recheck) == 0)
    addWorker(null, false);

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

int wc = workerCountOf(c);
if (wc >= CAPACITY ||
  wc >= (core ? corePoolSize : maximumPoolSize))

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

/**
 * Starts a core thread, causing it to idly wait for work. This
 * overrides the default policy of starting core threads only when
 * new tasks are executed. This method will return {@code false}
 * if all core threads have already been started.
 *
 * @return {@code true} if a thread was started
 */
public boolean prestartCoreThread() {
  return workerCountOf(ctl.get()) < corePoolSize &&
    addWorker(null, true);
}

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

/**
 * Starts a core thread, causing it to idly wait for work. This
 * overrides the default policy of starting core threads only when
 * new tasks are executed. This method will return {@code false}
 * if all core threads have already been started.
 *
 * @return {@code true} if a thread was started
 */
public boolean prestartCoreThread() {
  return workerCountOf(ctl.get()) < corePoolSize &&
    addWorker(null, true);
}

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

/**
 * Starts a core thread, causing it to idly wait for work. This
 * overrides the default policy of starting core threads only when
 * new tasks are executed. This method will return {@code false}
 * if all core threads have already been started.
 *
 * @return {@code true} if a thread was started
 */
public boolean prestartCoreThread() {
  return workerCountOf(ctl.get()) < corePoolSize &&
    addWorker(null, true);
}

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

/**
 * Starts a core thread, causing it to idly wait for work. This
 * overrides the default policy of starting core threads only when
 * new tasks are executed. This method will return {@code false}
 * if all core threads have already been started.
 *
 * @return {@code true} if a thread was started
 */
public boolean prestartCoreThread() {
  return workerCountOf(ctl.get()) < corePoolSize &&
    addWorker(null, true);
}

代码示例来源:origin: org.apidesign.bck2brwsr/emul

/**
 * Starts a core thread, causing it to idly wait for work. This
 * overrides the default policy of starting core threads only when
 * new tasks are executed. This method will return {@code false}
 * if all core threads have already been started.
 *
 * @return {@code true} if a thread was started
 */
public boolean prestartCoreThread() {
  return workerCountOf(ctl.get()) < corePoolSize &&
    addWorker(null, true);
}

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

/**
 * Starts a core thread, causing it to idly wait for work. This
 * overrides the default policy of starting core threads only when
 * new tasks are executed. This method will return {@code false}
 * if all core threads have already been started.
 *
 * @return {@code true} if a thread was started
 */
public boolean prestartCoreThread() {
  return workerCountOf(ctl.get()) < corePoolSize &&
    addWorker(null, true);
}

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

/**
 * Same as prestartCoreThread except arranges that at least one
 * thread is started even if corePoolSize is 0.
 */
void ensurePrestart() {
  int wc = workerCountOf(ctl.get());
  if (wc < corePoolSize)
    addWorker(null, true);
  else if (wc == 0)
    addWorker(null, false);
}

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

/**
 * Same as prestartCoreThread except arranges that at least one
 * thread is started even if corePoolSize is 0.
 */
void ensurePrestart() {
  int wc = workerCountOf(ctl.get());
  if (wc < corePoolSize)
    addWorker(null, true);
  else if (wc == 0)
    addWorker(null, false);
}

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

/**
 * Same as prestartCoreThread except arranges that at least one
 * thread is started even if corePoolSize is 0.
 */
void ensurePrestart() {
  int wc = workerCountOf(ctl.get());
  if (wc < corePoolSize)
    addWorker(null, true);
  else if (wc == 0)
    addWorker(null, false);
}

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

/**
 * Same as prestartCoreThread except arranges that at least one
 * thread is started even if corePoolSize is 0.
 */
void ensurePrestart() {
  int wc = workerCountOf(ctl.get());
  if (wc < corePoolSize)
    addWorker(null, true);
  else if (wc == 0)
    addWorker(null, false);
}

相关文章

ThreadPoolExecutor类方法