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; + } + } + }