optimize: 修改线程池变更后的日志打印.

pull/161/head
龙台 3 years ago
parent fa9b67f245
commit d1df7ad410

@ -114,4 +114,4 @@ POST http://localhost:6691/v1/cs/configs
<br/>
![](https://images-machen.oss-cn-beijing.aliyuncs.com/image-20210715124650132.png)
![](https://images-machen.oss-cn-beijing.aliyuncs.com/image-20210804082501860.png)

@ -31,30 +31,25 @@ public class ThreadPoolDynamicRefresh {
public static void refreshDynamicPool(String threadPoolId, Integer coreSize, Integer maxSize, Integer queueType, Integer capacity, Integer keepAliveTime, Integer rejectedType) {
ThreadPoolExecutor executor = GlobalThreadPoolManage.getExecutorService(threadPoolId).getPool();
printLog("[🔥] Original thread pool. ",
threadPoolId,
executor.getCorePoolSize(),
executor.getMaximumPoolSize(),
queueType,
(executor.getQueue().remainingCapacity() + executor.getQueue().size()),
executor.getKeepAliveTime(TimeUnit.MILLISECONDS),
rejectedType);
int originalCoreSize = executor.getCorePoolSize();
int originalMaximumPoolSize = executor.getMaximumPoolSize();
int originalQueryType = queueType;
int originalCapacity = executor.getQueue().remainingCapacity() + executor.getQueue().size();
long originalKeepAliveTime = executor.getKeepAliveTime(TimeUnit.MILLISECONDS);
int originalRejectedType = rejectedType;
changePoolInfo(executor, coreSize, maxSize, queueType, capacity, keepAliveTime, rejectedType);
ThreadPoolExecutor afterExecutor = GlobalThreadPoolManage.getExecutorService(threadPoolId).getPool();
printLog("[🚀] Changed thread pool. ",
threadPoolId,
afterExecutor.getCorePoolSize(),
afterExecutor.getMaximumPoolSize(),
queueType,
(afterExecutor.getQueue().remainingCapacity() + afterExecutor.getQueue().size()),
afterExecutor.getKeepAliveTime(TimeUnit.MILLISECONDS),
rejectedType);
}
private static void printLog(String tpId, String prefixMsg, Integer coreSize, Integer maxSize, Integer queueType, Integer capacity, Long keepAliveTime, Integer rejectedType) {
log.info("{} :: {}, coreSize :: {}, maxSize :: {}, queueType :: {}, capacity :: {}, keepAliveTime :: {}, rejectedType:: {}", tpId, prefixMsg, coreSize, maxSize, queueType, capacity, keepAliveTime, rejectedType);
log.info("[🔥 {}] Changed thread pool. coreSize :: [{}], maxSize :: [{}], queueType :: [{}], capacity :: [{}], keepAliveTime :: [{}], rejectedType :: [{}]",
threadPoolId.toUpperCase(),
String.format("%s=>%s", originalCoreSize, afterExecutor.getCorePoolSize()),
String.format("%s=>%s", originalMaximumPoolSize, afterExecutor.getMaximumPoolSize()),
String.format("%s=>%s", originalQueryType, queueType),
String.format("%s=>%s", originalCapacity, (afterExecutor.getQueue().remainingCapacity() + afterExecutor.getQueue().size())),
String.format("%s=>%s", originalKeepAliveTime, afterExecutor.getKeepAliveTime(TimeUnit.MILLISECONDS)),
String.format("%s=>%s", originalRejectedType, rejectedType));
}
public static void changePoolInfo(ThreadPoolExecutor executor, Integer coreSize, Integer maxSize, Integer queueType, Integer capacity, Integer keepAliveTime, Integer rejectedType) {
@ -83,4 +78,5 @@ public class ThreadPoolDynamicRefresh {
executor.setRejectedExecutionHandler(RejectedTypeEnum.createPolicy(queueType));
}
}
}

Loading…
Cancel
Save