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

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

@ -114,4 +114,4 @@ POST http://localhost:6691/v1/cs/configs
<br/> <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) { public static void refreshDynamicPool(String threadPoolId, Integer coreSize, Integer maxSize, Integer queueType, Integer capacity, Integer keepAliveTime, Integer rejectedType) {
ThreadPoolExecutor executor = GlobalThreadPoolManage.getExecutorService(threadPoolId).getPool(); ThreadPoolExecutor executor = GlobalThreadPoolManage.getExecutorService(threadPoolId).getPool();
printLog("[🔥] Original thread pool. ",
threadPoolId, int originalCoreSize = executor.getCorePoolSize();
executor.getCorePoolSize(), int originalMaximumPoolSize = executor.getMaximumPoolSize();
executor.getMaximumPoolSize(), int originalQueryType = queueType;
queueType, int originalCapacity = executor.getQueue().remainingCapacity() + executor.getQueue().size();
(executor.getQueue().remainingCapacity() + executor.getQueue().size()), long originalKeepAliveTime = executor.getKeepAliveTime(TimeUnit.MILLISECONDS);
executor.getKeepAliveTime(TimeUnit.MILLISECONDS), int originalRejectedType = rejectedType;
rejectedType);
changePoolInfo(executor, coreSize, maxSize, queueType, capacity, keepAliveTime, rejectedType); changePoolInfo(executor, coreSize, maxSize, queueType, capacity, keepAliveTime, rejectedType);
ThreadPoolExecutor afterExecutor = GlobalThreadPoolManage.getExecutorService(threadPoolId).getPool(); ThreadPoolExecutor afterExecutor = GlobalThreadPoolManage.getExecutorService(threadPoolId).getPool();
printLog("[🚀] Changed thread pool. ", log.info("[🔥 {}] Changed thread pool. coreSize :: [{}], maxSize :: [{}], queueType :: [{}], capacity :: [{}], keepAliveTime :: [{}], rejectedType :: [{}]",
threadPoolId, threadPoolId.toUpperCase(),
afterExecutor.getCorePoolSize(), String.format("%s=>%s", originalCoreSize, afterExecutor.getCorePoolSize()),
afterExecutor.getMaximumPoolSize(), String.format("%s=>%s", originalMaximumPoolSize, afterExecutor.getMaximumPoolSize()),
queueType, String.format("%s=>%s", originalQueryType, queueType),
(afterExecutor.getQueue().remainingCapacity() + afterExecutor.getQueue().size()), String.format("%s=>%s", originalCapacity, (afterExecutor.getQueue().remainingCapacity() + afterExecutor.getQueue().size())),
afterExecutor.getKeepAliveTime(TimeUnit.MILLISECONDS), String.format("%s=>%s", originalKeepAliveTime, afterExecutor.getKeepAliveTime(TimeUnit.MILLISECONDS)),
rejectedType); String.format("%s=>%s", originalRejectedType, 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);
} }
public static void changePoolInfo(ThreadPoolExecutor executor, Integer coreSize, Integer maxSize, Integer queueType, Integer capacity, Integer keepAliveTime, Integer 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)); executor.setRejectedExecutionHandler(RejectedTypeEnum.createPolicy(queueType));
} }
} }
} }

Loading…
Cancel
Save