Configure refresh code optimization

pull/531/head
chen.ma 2 years ago
parent 9f797ca91a
commit 1da8eda1ad

@ -61,13 +61,7 @@ public class ServerThreadPoolDynamicRefresh implements ThreadPoolDynamicRefresh
refreshDynamicPool(parameter, executor); refreshDynamicPool(parameter, executor);
} }
/** private void refreshDynamicPool(ThreadPoolParameter parameter, ThreadPoolExecutor executor) {
* Refresh dynamic pool.
*
* @param parameter
* @param executor
*/
public void refreshDynamicPool(ThreadPoolParameter parameter, ThreadPoolExecutor executor) {
String threadPoolId = parameter.getTpId(); String threadPoolId = parameter.getTpId();
int originalCoreSize = executor.getCorePoolSize(); int originalCoreSize = executor.getCorePoolSize();
int originalMaximumPoolSize = executor.getMaximumPoolSize(); int originalMaximumPoolSize = executor.getMaximumPoolSize();
@ -82,29 +76,29 @@ public class ServerThreadPoolDynamicRefresh implements ThreadPoolDynamicRefresh
rejectedExecutionHandler = dynamicExecutor.getRedundancyHandler(); rejectedExecutionHandler = dynamicExecutor.getRedundancyHandler();
originalExecuteTimeOut = dynamicExecutor.getExecuteTimeOut(); originalExecuteTimeOut = dynamicExecutor.getExecuteTimeOut();
} }
String originalRejected = rejectedExecutionHandler.getClass().getSimpleName();
// Send change message.
ChangeParameterNotifyRequest request = new ChangeParameterNotifyRequest();
request.setBeforeCorePoolSize(originalCoreSize);
request.setBeforeMaximumPoolSize(originalMaximumPoolSize);
request.setBeforeAllowsCoreThreadTimeOut(originalAllowCoreThreadTimeOut);
request.setBeforeKeepAliveTime(originalKeepAliveTime);
request.setBlockingQueueName(originalQuery);
request.setBeforeQueueCapacity(originalCapacity);
request.setBeforeRejectedName(originalRejected);
request.setBeforeExecuteTimeOut(originalExecuteTimeOut);
request.setThreadPoolId(threadPoolId);
changePoolInfo(executor, parameter); changePoolInfo(executor, parameter);
Long executeTimeOut = Optional.ofNullable(parameter.getExecuteTimeOut()).orElse(0L);
ThreadPoolExecutor afterExecutor = GlobalThreadPoolManage.getExecutorService(threadPoolId).getExecutor(); ThreadPoolExecutor afterExecutor = GlobalThreadPoolManage.getExecutorService(threadPoolId).getExecutor();
request.setNowCorePoolSize(afterExecutor.getCorePoolSize()); String originalRejected = rejectedExecutionHandler.getClass().getSimpleName();
request.setNowMaximumPoolSize(afterExecutor.getMaximumPoolSize()); Long executeTimeOut = Optional.ofNullable(parameter.getExecuteTimeOut()).orElse(0L);
request.setNowAllowsCoreThreadTimeOut(EnableEnum.getBool(parameter.getAllowCoreThreadTimeOut())); ChangeParameterNotifyRequest changeNotifyRequest = ChangeParameterNotifyRequest.builder()
request.setNowKeepAliveTime(afterExecutor.getKeepAliveTime(TimeUnit.SECONDS)); .beforeCorePoolSize(originalCoreSize)
request.setNowQueueCapacity((afterExecutor.getQueue().remainingCapacity() + afterExecutor.getQueue().size())); .beforeMaximumPoolSize(originalMaximumPoolSize)
request.setNowRejectedName(RejectedTypeEnum.getRejectedNameByType(parameter.getRejectedType())); .beforeAllowsCoreThreadTimeOut(originalAllowCoreThreadTimeOut)
request.setNowExecuteTimeOut(executeTimeOut); .beforeKeepAliveTime(originalKeepAliveTime)
threadPoolNotifyAlarmHandler.sendPoolConfigChange(request); .blockingQueueName(originalQuery)
.beforeQueueCapacity(originalCapacity)
.beforeRejectedName(originalRejected)
.beforeExecuteTimeOut(originalExecuteTimeOut)
.nowCorePoolSize(afterExecutor.getCorePoolSize())
.nowMaximumPoolSize(afterExecutor.getMaximumPoolSize())
.nowAllowsCoreThreadTimeOut(EnableEnum.getBool(parameter.getAllowCoreThreadTimeOut()))
.nowKeepAliveTime(afterExecutor.getKeepAliveTime(TimeUnit.SECONDS))
.nowQueueCapacity((afterExecutor.getQueue().remainingCapacity() + afterExecutor.getQueue().size()))
.nowRejectedName(RejectedTypeEnum.getRejectedNameByType(parameter.getRejectedType()))
.nowExecuteTimeOut(executeTimeOut)
.build();
changeNotifyRequest.setThreadPoolId(threadPoolId);
threadPoolNotifyAlarmHandler.sendPoolConfigChange(changeNotifyRequest);
log.info(CHANGE_THREAD_POOL_TEXT, log.info(CHANGE_THREAD_POOL_TEXT,
threadPoolId, threadPoolId,
String.format(CHANGE_DELIMITER, originalCoreSize, afterExecutor.getCorePoolSize()), String.format(CHANGE_DELIMITER, originalCoreSize, afterExecutor.getCorePoolSize()),
@ -116,13 +110,7 @@ public class ServerThreadPoolDynamicRefresh implements ThreadPoolDynamicRefresh
String.format(CHANGE_DELIMITER, originalAllowCoreThreadTimeOut, EnableEnum.getBool(parameter.getAllowCoreThreadTimeOut()))); String.format(CHANGE_DELIMITER, originalAllowCoreThreadTimeOut, EnableEnum.getBool(parameter.getAllowCoreThreadTimeOut())));
} }
/** private void changePoolInfo(ThreadPoolExecutor executor, ThreadPoolParameter parameter) {
* Change pool info.
*
* @param executor
* @param parameter
*/
public void changePoolInfo(ThreadPoolExecutor executor, ThreadPoolParameter parameter) {
if (parameter.getCoreSize() != null && parameter.getMaxSize() != null) { if (parameter.getCoreSize() != null && parameter.getMaxSize() != null) {
if (parameter.getMaxSize() < executor.getMaximumPoolSize()) { if (parameter.getMaxSize() < executor.getMaximumPoolSize()) {
executor.setCorePoolSize(parameter.getCoreSize()); executor.setCorePoolSize(parameter.getCoreSize());

Loading…
Cancel
Save