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


Java ThreadPoolExecutor.getActiveCount方法代码示例

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


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

示例1: check

import java.util.concurrent.ThreadPoolExecutor; //导入方法依赖的package包/类
public Status check() {
    DataStore dataStore = ExtensionLoader.getExtensionLoader(DataStore.class).getDefaultExtension();
    Map<String, Object> executors = dataStore.get(Constants.EXECUTOR_SERVICE_COMPONENT_KEY);

    StringBuilder msg = new StringBuilder();
    Status.Level level = Status.Level.OK;
    for(Map.Entry<String, Object> entry : executors.entrySet()) {
        String port = entry.getKey();
        ExecutorService executor = (ExecutorService) entry.getValue();

        if (executor != null && executor instanceof ThreadPoolExecutor) {
            ThreadPoolExecutor tp = (ThreadPoolExecutor) executor;
            boolean ok = tp.getActiveCount() < tp.getMaximumPoolSize() - 1;
            Status.Level lvl = Status.Level.OK;
            if(!ok) {
                level = Status.Level.WARN;
                lvl = Status.Level.WARN;
            }

            if(msg.length() > 0) {
                msg.append(";");
            }
            msg.append("Pool status:" + lvl
                    + ", max:" + tp.getMaximumPoolSize()
                    + ", core:" + tp.getCorePoolSize()
                    + ", largest:" + tp.getLargestPoolSize()
                    + ", active:" + tp.getActiveCount()
                    + ", task:" + tp.getTaskCount()
                    + ", service port: " + port);
        }
    }
    return msg.length() == 0 ? new Status(Status.Level.UNKNOWN) : new Status(level, msg.toString());
}
 
开发者ID:dachengxi,项目名称:EatDubbo,代码行数:34,代码来源:ThreadPoolStatusChecker.java

示例2: getThreadActiveSize

import java.util.concurrent.ThreadPoolExecutor; //导入方法依赖的package包/类
public int getThreadActiveSize() {
    if (executorService instanceof ThreadPoolExecutor) {
        ThreadPoolExecutor pool = (ThreadPoolExecutor) executorService;
        return pool.getActiveCount();
    }

    return 0;
}
 
开发者ID:luoyaogui,项目名称:otter-G,代码行数:9,代码来源:OtterController.java

示例3: awaitIdleness

import java.util.concurrent.ThreadPoolExecutor; //导入方法依赖的package包/类
static void awaitIdleness(ThreadPoolExecutor tpe, long taskCount) {
    restart: for (;;) {
        // check twice to make chance of race vanishingly small
        for (int i = 0; i < 2; i++) {
            if (tpe.getQueue().size() != 0 ||
                tpe.getActiveCount() != 0 ||
                tpe.getCompletedTaskCount() != taskCount) {
                Thread.yield();
                continue restart;
            }
        }
        return;
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:15,代码来源:ConfigChanges.java

示例4: process

import java.util.concurrent.ThreadPoolExecutor; //导入方法依赖的package包/类
/**
 * Adds the distribution manager that is started up to the current DM's list of members.
 *
 * This method is invoked on the receiver side
 */
@Override
protected void process(DistributionManager dm) {
  switch (this.op) {
    case DRAIN_POOL:
      Assert.assertTrue(this.id != null);
      // wait 10 seconds for the high priority queue to drain
      long endTime = System.currentTimeMillis() + 10000;
      ThreadPoolExecutor pool = (ThreadPoolExecutor) dm.getHighPriorityThreadPool();
      while (pool.getActiveCount() > 1 && System.currentTimeMillis() < endTime) {
        boolean interrupted = Thread.interrupted();
        try {
          Thread.sleep(500);
        } catch (InterruptedException ie) {
          interrupted = true;
          dm.getCancelCriterion().checkCancelInProgress(ie);
          // if interrupted, we must be shutting down
          return;
        } finally {
          if (interrupted)
            Thread.currentThread().interrupt();
        }
      }
      if (pool.getActiveCount() > 1) {

        logger.warn(LocalizedMessage.create(
            LocalizedStrings.HighPriorityAckedMessage_0_THERE_ARE_STILL_1_OTHER_THREADS_ACTIVE_IN_THE_HIGH_PRIORITY_THREAD_POOL,
            new Object[] {this, Integer.valueOf(pool.getActiveCount() - 1)}));
      }
      ReplyMessage.send(getSender(), processorId, null, dm);
      break;
    case DUMP_STACK:
      if (this.processorId > 0) {
        try {
          byte[] zippedStacks = OSProcess.zipStacks();
          ReplyMessage.send(getSender(), processorId, zippedStacks, dm);
        } catch (IOException e) {
          ReplyMessage.send(getSender(), processorId, new ReplyException(e), dm);
        }
      } else {
        OSProcess.printStacks(0, this.useNative);
      }
  }
}
 
开发者ID:ampool,项目名称:monarch,代码行数:49,代码来源:HighPriorityAckedMessage.java


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