-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExecutorUtils.java
More file actions
35 lines (28 loc) · 1.4 KB
/
Copy pathExecutorUtils.java
File metadata and controls
35 lines (28 loc) · 1.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
package thread.executor;
import util.MyLogger;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.ThreadPoolExecutor;
public class ExecutorUtils {
public static void printState(ExecutorService executorService){
if(executorService instanceof ThreadPoolExecutor threadPoolExecutor){
int pool = threadPoolExecutor.getPoolSize();
int active = threadPoolExecutor.getActiveCount();
int queue = threadPoolExecutor.getQueue().size();
long completeTask = threadPoolExecutor.getCompletedTaskCount();
MyLogger.log("[pool=" + pool + ", active=" + active + ", queueTasks=" + queue + ", completedTask=" + completeTask + "]");
} else {
MyLogger.log(executorService);
}
}
public static void printState(ExecutorService executorService, String taskName){
if(executorService instanceof ThreadPoolExecutor threadPoolExecutor){
int pool = threadPoolExecutor.getPoolSize();
int active = threadPoolExecutor.getActiveCount();
int queue = threadPoolExecutor.getQueue().size();
long completeTask = threadPoolExecutor.getCompletedTaskCount();
MyLogger.log(taskName + "-> [pool=" + pool + ", active=" + active + ", queueTasks=" + queue + ", completedTask=" + completeTask + "]");
} else {
MyLogger.log(executorService);
}
}
}