From e2566a1e394ff0e417ace7cdcc0ec8d14387a2e9 Mon Sep 17 00:00:00 2001 From: wanggeng <450292408@qq.com> Date: Sat, 4 Jun 2022 11:00:45 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E7=8A=B6=E6=80=81=E7=B1=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../util/thread/CachedThreadPoolUtil.java | 43 +++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/basic-util/src/main/java/ink/wgink/util/thread/CachedThreadPoolUtil.java b/basic-util/src/main/java/ink/wgink/util/thread/CachedThreadPoolUtil.java index 735f60e3..ef92c557 100644 --- a/basic-util/src/main/java/ink/wgink/util/thread/CachedThreadPoolUtil.java +++ b/basic-util/src/main/java/ink/wgink/util/thread/CachedThreadPoolUtil.java @@ -36,5 +36,48 @@ public class CachedThreadPoolUtil { executorService.execute(runnable); } + /** + * 状态 + * + * @return + */ + public static Status getStatus() { + ThreadPoolExecutor threadPoolExecutor = (ThreadPoolExecutor) executorService; + return new Status(threadPoolExecutor.getQueue().size(), + threadPoolExecutor.getActiveCount(), + threadPoolExecutor.getCompletedTaskCount(), + threadPoolExecutor.getTaskCount()); + } + + public static class Status { + private Integer queueSize; + private Integer activeCount; + private Long completedTaskCount; + private Long totalTaskCount; + + public Status(Integer queueSize, Integer activeCount, Long completedTaskCount, Long totalTaskCount) { + this.queueSize = queueSize; + this.activeCount = activeCount; + this.completedTaskCount = completedTaskCount; + this.totalTaskCount = totalTaskCount; + } + + public Integer getQueueSize() { + return queueSize == null ? 0 : queueSize; + } + + public Integer getActiveCount() { + return activeCount == null ? 0 : activeCount; + } + + public Long getCompletedTaskCount() { + return completedTaskCount == null ? 0 : completedTaskCount; + } + + public Long getTotalTaskCount() { + return totalTaskCount == null ? 0 : totalTaskCount; + } + } + }