當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。