|
|
@ -1,9 +1,11 @@
|
|
|
|
package com.github.dynamic.threadpool.starter.handler;
|
|
|
|
package com.github.dynamic.threadpool.starter.handler;
|
|
|
|
|
|
|
|
|
|
|
|
import com.github.dynamic.threadpool.starter.wrap.DynamicThreadPoolWrap;
|
|
|
|
|
|
|
|
import com.github.dynamic.threadpool.common.model.PoolRunStateInfo;
|
|
|
|
import com.github.dynamic.threadpool.common.model.PoolRunStateInfo;
|
|
|
|
import com.github.dynamic.threadpool.starter.core.GlobalThreadPoolManage;
|
|
|
|
import com.github.dynamic.threadpool.starter.core.GlobalThreadPoolManage;
|
|
|
|
|
|
|
|
import com.github.dynamic.threadpool.starter.toolkit.CalculateUtil;
|
|
|
|
import com.github.dynamic.threadpool.starter.toolkit.thread.CustomThreadPoolExecutor;
|
|
|
|
import com.github.dynamic.threadpool.starter.toolkit.thread.CustomThreadPoolExecutor;
|
|
|
|
|
|
|
|
import com.github.dynamic.threadpool.starter.wrap.DynamicThreadPoolWrap;
|
|
|
|
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
|
|
|
|
|
|
|
import java.net.InetAddress;
|
|
|
|
import java.net.InetAddress;
|
|
|
|
import java.net.UnknownHostException;
|
|
|
|
import java.net.UnknownHostException;
|
|
|
@ -16,6 +18,7 @@ import java.util.concurrent.ThreadPoolExecutor;
|
|
|
|
* @author chen.ma
|
|
|
|
* @author chen.ma
|
|
|
|
* @date 2021/7/12 21:25
|
|
|
|
* @date 2021/7/12 21:25
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
|
|
|
|
@Slf4j
|
|
|
|
public class ThreadPoolRunStateHandler {
|
|
|
|
public class ThreadPoolRunStateHandler {
|
|
|
|
|
|
|
|
|
|
|
|
private static InetAddress addr;
|
|
|
|
private static InetAddress addr;
|
|
|
@ -23,9 +26,8 @@ public class ThreadPoolRunStateHandler {
|
|
|
|
static {
|
|
|
|
static {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
addr = InetAddress.getLocalHost();
|
|
|
|
addr = InetAddress.getLocalHost();
|
|
|
|
|
|
|
|
} catch (UnknownHostException ex) {
|
|
|
|
} catch (UnknownHostException e) {
|
|
|
|
log.error("Local IP acquisition failed.", ex);
|
|
|
|
e.printStackTrace();
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -46,9 +48,9 @@ public class ThreadPoolRunStateHandler {
|
|
|
|
// 线程池中执行任务总数量
|
|
|
|
// 线程池中执行任务总数量
|
|
|
|
long completedTaskCount = pool.getCompletedTaskCount();
|
|
|
|
long completedTaskCount = pool.getCompletedTaskCount();
|
|
|
|
// 当前负载
|
|
|
|
// 当前负载
|
|
|
|
String currentLoad = divide(activeCount, maximumPoolSize);
|
|
|
|
String currentLoad = CalculateUtil.divide(activeCount, maximumPoolSize) + "%";
|
|
|
|
// 峰值负载
|
|
|
|
// 峰值负载
|
|
|
|
String peakLoad = divide(largestPoolSize, maximumPoolSize);
|
|
|
|
String peakLoad = CalculateUtil.divide(largestPoolSize, maximumPoolSize) + "%";
|
|
|
|
|
|
|
|
|
|
|
|
BlockingQueue<Runnable> queue = pool.getQueue();
|
|
|
|
BlockingQueue<Runnable> queue = pool.getQueue();
|
|
|
|
// 队列类型
|
|
|
|
// 队列类型
|
|
|
@ -84,8 +86,4 @@ public class ThreadPoolRunStateHandler {
|
|
|
|
return stateInfo;
|
|
|
|
return stateInfo;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private static String divide(int num1, int num2) {
|
|
|
|
|
|
|
|
return ((int) (Double.parseDouble(num1 + "") / Double.parseDouble(num2 + "") * 100)) + "%";
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|