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

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

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

ThreadPoolExecutor.getTaskCount介绍

[英]Returns the approximate total number of tasks that have ever been scheduled for execution. Because the states of tasks and threads may change dynamically during computation, the returned value is only an approximation.
[中]返回计划执行的任务的大致总数。由于任务和线程的状态在计算过程中可能会动态变化,因此返回的值只是一个近似值。

代码示例

代码示例来源:origin: PipelineAI/pipeline

/**
 * Value from {@link ThreadPoolExecutor#getTaskCount()}
 * 
 * @return Number
 */
public Number getCurrentTaskCount() {
  return threadPool.getTaskCount();
}

代码示例来源:origin: apache/hbase

@Override
public long getPoolTaskCount() {
 return pool.getTaskCount();
}

代码示例来源:origin: apache/ignite

/** {@inheritDoc} */
@Override public long getTaskCount() {
  return exec instanceof ThreadPoolExecutor ? ((ThreadPoolExecutor)exec).getTaskCount() : -1;
}

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

@Override
public long getTaskCount() {
  return executor.getTaskCount();
}

代码示例来源:origin: osmandapp/Osmand

public int getRemainingWorkers() {
  return (int) (threadPoolExecutor.getTaskCount());
}

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

public long getTaskCount() {
  return executor.getTaskCount();
}

代码示例来源:origin: skylot/jadx

public int getProgress() {
    return (int) (executor.getCompletedTaskCount() * 100 / (double) executor.getTaskCount());
  }
}

代码示例来源:origin: stanfordnlp/CoreNLP

/**
 * Return status information about the underlying threadpool.
 */
@Override
public String toString() {
 return String.format("active: %d/%d  submitted: %d  completed: %d  input_q: %d  output_q: %d  idle_q: %d",
   threadPool.getActiveCount(),
   threadPool.getPoolSize(),
   threadPool.getTaskCount(),
   threadPool.getCompletedTaskCount(),
   threadPool.getQueue().size(),
   outputQueue.size(),
   idleProcessors.size());
}

代码示例来源:origin: Netflix/servo

@com.netflix.servo.annotations.Monitor(name = "taskCount", type = COUNTER)
 long getTaskCount() {
  return pool.getTaskCount();
 }
}

代码示例来源:origin: lealone/Lealone

public Long value() {
    return executor.getTaskCount() - executor.getCompletedTaskCount();
  }
});

代码示例来源:origin: apache/incubator-dubbo

@Override
public void rejectedExecution(Runnable r, ThreadPoolExecutor e) {
  String msg = String.format("Thread pool is EXHAUSTED!" +
          " Thread Name: %s, Pool Size: %d (active: %d, core: %d, max: %d, largest: %d), Task: %d (completed: %d)," +
          " Executor status:(isShutdown:%s, isTerminated:%s, isTerminating:%s), in %s://%s:%d!",
      threadName, e.getPoolSize(), e.getActiveCount(), e.getCorePoolSize(), e.getMaximumPoolSize(), e.getLargestPoolSize(),
      e.getTaskCount(), e.getCompletedTaskCount(), e.isShutdown(), e.isTerminated(), e.isTerminating(),
      url.getProtocol(), url.getIp(), url.getPort());
  logger.warn(msg);
  dumpJStack();
  throw new RejectedExecutionException(msg);
}

代码示例来源:origin: apache/incubator-dubbo

@Override
public void rejectedExecution(Runnable r, ThreadPoolExecutor e) {
  String msg = String.format("Thread pool is EXHAUSTED!" +
          " Thread Name: %s, Pool Size: %d (active: %d, core: %d, max: %d, largest: %d), Task: %d (completed: %d)," +
          " Executor status:(isShutdown:%s, isTerminated:%s, isTerminating:%s), in %s://%s:%d!",
      threadName, e.getPoolSize(), e.getActiveCount(), e.getCorePoolSize(), e.getMaximumPoolSize(), e.getLargestPoolSize(),
      e.getTaskCount(), e.getCompletedTaskCount(), e.isShutdown(), e.isTerminated(), e.isTerminating(),
      url.getProtocol(), url.getIp(), url.getPort());
  logger.warn(msg);
  dumpJStack();
  throw new RejectedExecutionException(msg);
}

代码示例来源:origin: apache/incubator-dubbo

+ ", largest:" + tp.getLargestPoolSize()
+ ", active:" + tp.getActiveCount()
+ ", task:" + tp.getTaskCount()
+ ", service port: " + port);

代码示例来源:origin: apache/incubator-dubbo

+ ", largest:" + tp.getLargestPoolSize()
+ ", active:" + tp.getActiveCount()
+ ", task:" + tp.getTaskCount()
+ ", service port: " + port);

代码示例来源:origin: vipshop/vjtools

@Override
public void rejectedExecution(Runnable r, ThreadPoolExecutor e) {
  String msg = String.format(
      "Thread pool is EXHAUSTED!"
          + " Thread Name: %s, Pool Size: %d (active: %d, core: %d, max: %d, largest: %d), Task: %d (completed: %d),"
          + " Executor status:(isShutdown:%s, isTerminated:%s, isTerminating:%s)!",
      threadName, e.getPoolSize(), e.getActiveCount(), e.getCorePoolSize(), e.getMaximumPoolSize(),
      e.getLargestPoolSize(), e.getTaskCount(), e.getCompletedTaskCount(), e.isShutdown(), e.isTerminated(),
      e.isTerminating());
  logger.warn(msg);
  dummper.tryThreadDump(null);
  throw new RejectedExecutionException(msg);
}

代码示例来源:origin: alipay/sofa-rpc

@Override
  public void rejectedExecution(Runnable r, ThreadPoolExecutor executor) {
    if (i++ % 7 == 0) {
      i = 1;
      if (LOGGER.isWarnEnabled()) {
        LOGGER.warn("Task:{} has been reject because of threadPool exhausted!" +
          " pool:{}, active:{}, queue:{}, taskcnt: {}", r,
          executor.getPoolSize(),
          executor.getActiveCount(),
          executor.getQueue().size(),
          executor.getTaskCount());
      }
    }
    throw new RejectedExecutionException("Callback handler thread pool has bean exhausted");
  }
};

代码示例来源:origin: alipay/sofa-rpc

@Override
  public void rejectedExecution(Runnable r, ThreadPoolExecutor executor) {
    if (i++ % 7 == 0) {
      i = 1;
      if (LOGGER.isWarnEnabled()) {
        LOGGER.warn("Task:{} has been reject because of threadPool exhausted!" +
          " pool:{}, active:{}, queue:{}, taskcnt: {}", r,
          executor.getPoolSize(),
          executor.getActiveCount(),
          executor.getQueue().size(),
          executor.getTaskCount());
      }
    }
    throw new RejectedExecutionException("Callback handler thread pool has bean exhausted");
  }
};

代码示例来源:origin: skylot/jadx

@Override
  public void run() {
    try {
      decompiler.getArgs().setRootDir(dir);
      ThreadPoolExecutor ex = (ThreadPoolExecutor) decompiler.getSaveExecutor();
      ex.shutdown();
      while (ex.isTerminating()) {
        long total = ex.getTaskCount();
        long done = ex.getCompletedTaskCount();
        progressMonitor.setProgress((int) (done * 100.0 / (double) total));
        Thread.sleep(500);
      }
      progressMonitor.close();
      LOG.info("decompilation complete, freeing memory ...");
      decompiler.getClasses().forEach(JavaClass::unload);
      LOG.info("done");
    } catch (InterruptedException e) {
      LOG.error("Save interrupted", e);
      Thread.currentThread().interrupt();
    }
  }
};

代码示例来源:origin: jphp-group/jphp

@Signature
public Memory getTaskCount(Environment env, Memory... args) {
  if (service instanceof ThreadPoolExecutor) {
    return LongMemory.valueOf(((ThreadPoolExecutor) service).getTaskCount());
  }
  return Memory.NULL;
}

代码示例来源:origin: weibocom/motan

private void rejectMessage(ChannelHandlerContext ctx, NettyMessage msg) {
  if (msg.isRequest()) {
    DefaultResponse response = new DefaultResponse();
    response.setRequestId(msg.getRequestId());
    response.setException(new MotanServiceException("process thread pool is full, reject by server: " + ctx.channel().localAddress(), MotanErrorMsgConstant.SERVICE_REJECT));
    sendResponse(ctx, response);
    LoggerUtil.error("process thread pool is full, reject, active={} poolSize={} corePoolSize={} maxPoolSize={} taskCount={} requestId={}",
        threadPoolExecutor.getActiveCount(), threadPoolExecutor.getPoolSize(), threadPoolExecutor.getCorePoolSize(),
        threadPoolExecutor.getMaximumPoolSize(), threadPoolExecutor.getTaskCount(), msg.getRequestId());
    rejectCounter.incrementAndGet();
  }
}

相关文章

ThreadPoolExecutor类方法