diff --git a/hippo4j-core/src/main/java/cn/hippo4j/core/executor/DynamicThreadPoolExecutor.java b/hippo4j-core/src/main/java/cn/hippo4j/core/executor/DynamicThreadPoolExecutor.java index d8f96d8a..9bd3b0e1 100644 --- a/hippo4j-core/src/main/java/cn/hippo4j/core/executor/DynamicThreadPoolExecutor.java +++ b/hippo4j-core/src/main/java/cn/hippo4j/core/executor/DynamicThreadPoolExecutor.java @@ -85,7 +85,6 @@ public class DynamicThreadPoolExecutor extends AbstractDynamicExecutorSupport { if (taskDecorator != null) { command = taskDecorator.decorate(command); } - super.execute(command); } @@ -94,7 +93,6 @@ public class DynamicThreadPoolExecutor extends AbstractDynamicExecutorSupport { if (executeTimeOut == null || executeTimeOut <= 0) { return; } - this.startTime.set(SystemClock.now()); } @@ -103,7 +101,6 @@ public class DynamicThreadPoolExecutor extends AbstractDynamicExecutorSupport { if (executeTimeOut == null || executeTimeOut <= 0) { return; } - try { long startTime = this.startTime.get(); long endTime = SystemClock.now(); @@ -125,13 +122,7 @@ public class DynamicThreadPoolExecutor extends AbstractDynamicExecutorSupport { return this; } - /** - * Get reject count. - * - * @return - */ public Long getRejectCountNum() { return rejectCount.get(); } - } diff --git a/hippo4j-core/src/main/java/cn/hippo4j/core/executor/support/AbstractBuildThreadPoolTemplate.java b/hippo4j-core/src/main/java/cn/hippo4j/core/executor/support/AbstractBuildThreadPoolTemplate.java index 032ebb57..c9ca3a2b 100644 --- a/hippo4j-core/src/main/java/cn/hippo4j/core/executor/support/AbstractBuildThreadPoolTemplate.java +++ b/hippo4j-core/src/main/java/cn/hippo4j/core/executor/support/AbstractBuildThreadPoolTemplate.java @@ -230,5 +230,4 @@ public class AbstractBuildThreadPoolTemplate { .build(); } } - } diff --git a/hippo4j-core/src/main/java/cn/hippo4j/core/executor/support/ThreadPoolBuilder.java b/hippo4j-core/src/main/java/cn/hippo4j/core/executor/support/ThreadPoolBuilder.java index c9376519..71cf9487 100644 --- a/hippo4j-core/src/main/java/cn/hippo4j/core/executor/support/ThreadPoolBuilder.java +++ b/hippo4j-core/src/main/java/cn/hippo4j/core/executor/support/ThreadPoolBuilder.java @@ -123,6 +123,8 @@ public class ThreadPoolBuilder implements Builder { */ private Boolean allowCoreThreadTimeOut = false; + private Boolean prestartCoreThread = false; + /** * 计算公式:CPU 核数 / (1 - 阻塞系数 0.8) * diff --git a/hippo4j-spring-boot/hippo4j-core-spring-boot-starter/src/main/java/cn/hippo4j/core/starter/support/DynamicThreadPoolPostProcessor.java b/hippo4j-spring-boot/hippo4j-core-spring-boot-starter/src/main/java/cn/hippo4j/core/starter/support/DynamicThreadPoolPostProcessor.java index 3272a38d..af167910 100644 --- a/hippo4j-spring-boot/hippo4j-core-spring-boot-starter/src/main/java/cn/hippo4j/core/starter/support/DynamicThreadPoolPostProcessor.java +++ b/hippo4j-spring-boot/hippo4j-core-spring-boot-starter/src/main/java/cn/hippo4j/core/starter/support/DynamicThreadPoolPostProcessor.java @@ -65,7 +65,7 @@ public final class DynamicThreadPoolPostProcessor implements BeanPostProcessor { try { dynamicThreadPool = ApplicationContextHolder.findAnnotationOnBean(beanName, DynamicThreadPool.class); if (Objects.isNull(dynamicThreadPool)) { - // 适配低版本 SpringBoot + // Adapt to lower versions of SpringBoot. dynamicThreadPool = DynamicThreadPoolAnnotationUtil.findAnnotationOnBean(beanName, DynamicThreadPool.class); if (Objects.isNull(dynamicThreadPool)) { return bean; @@ -75,18 +75,15 @@ public final class DynamicThreadPoolPostProcessor implements BeanPostProcessor { log.error("Failed to create dynamic thread pool in annotation mode.", ex); return bean; } - DynamicThreadPoolExecutor dynamicExecutor = (DynamicThreadPoolExecutor) bean; DynamicThreadPoolWrapper wrap = new DynamicThreadPoolWrapper(dynamicExecutor.getThreadPoolId(), dynamicExecutor); ThreadPoolExecutor remoteExecutor = fillPoolAndRegister(wrap); return remoteExecutor; } - if (bean instanceof DynamicThreadPoolWrapper) { DynamicThreadPoolWrapper wrap = (DynamicThreadPoolWrapper) bean; registerAndSubscribe(wrap); } - return bean; } @@ -143,20 +140,15 @@ public final class DynamicThreadPoolPostProcessor implements BeanPostProcessor { // 设置动态线程池增强参数 ThreadPoolNotifyAlarm notify = Optional.ofNullable(executorProperties).map(ExecutorProperties::getNotify).orElse(null); boolean isAlarm = Optional.ofNullable(notify) - .map(each -> each.getIsAlarm()) - .orElseGet(() -> bootstrapCoreProperties.getAlarm() != null ? bootstrapCoreProperties.getAlarm() : true); + .map(each -> each.getIsAlarm()).orElseGet(() -> bootstrapCoreProperties.getAlarm() != null ? bootstrapCoreProperties.getAlarm() : true); int activeAlarm = Optional.ofNullable(notify) - .map(each -> each.getActiveAlarm()) - .orElseGet(() -> bootstrapCoreProperties.getActiveAlarm() != null ? bootstrapCoreProperties.getActiveAlarm() : 80); + .map(each -> each.getActiveAlarm()).orElseGet(() -> bootstrapCoreProperties.getActiveAlarm() != null ? bootstrapCoreProperties.getActiveAlarm() : 80); int capacityAlarm = Optional.ofNullable(notify) - .map(each -> each.getActiveAlarm()) - .orElseGet(() -> bootstrapCoreProperties.getCapacityAlarm() != null ? bootstrapCoreProperties.getCapacityAlarm() : 80); + .map(each -> each.getActiveAlarm()).orElseGet(() -> bootstrapCoreProperties.getCapacityAlarm() != null ? bootstrapCoreProperties.getCapacityAlarm() : 80); int interval = Optional.ofNullable(notify) - .map(each -> each.getInterval()) - .orElseGet(() -> bootstrapCoreProperties.getAlarmInterval() != null ? bootstrapCoreProperties.getAlarmInterval() : 5); + .map(each -> each.getInterval()).orElseGet(() -> bootstrapCoreProperties.getAlarmInterval() != null ? bootstrapCoreProperties.getAlarmInterval() : 5); String receive = Optional.ofNullable(notify) - .map(each -> each.getReceive()) - .orElseGet(() -> bootstrapCoreProperties.getReceive() != null ? bootstrapCoreProperties.getReceive() : null); + .map(each -> each.getReceive()).orElseGet(() -> bootstrapCoreProperties.getReceive() != null ? bootstrapCoreProperties.getReceive() : null); ThreadPoolNotifyAlarm threadPoolNotifyAlarm = new ThreadPoolNotifyAlarm(isAlarm, activeAlarm, capacityAlarm); threadPoolNotifyAlarm.setInterval(interval); threadPoolNotifyAlarm.setReceive(receive); @@ -169,7 +161,6 @@ public final class DynamicThreadPoolPostProcessor implements BeanPostProcessor { boolean waitForTasksToCompleteOnShutdown = ((DynamicThreadPoolExecutor) dynamicThreadPoolWrap.getExecutor()).waitForTasksToCompleteOnShutdown; ((DynamicThreadPoolExecutor) newDynamicPoolExecutor).setSupportParam(awaitTerminationMillis, waitForTasksToCompleteOnShutdown); } - dynamicThreadPoolWrap.setExecutor(newDynamicPoolExecutor); } @@ -179,7 +170,6 @@ public final class DynamicThreadPoolPostProcessor implements BeanPostProcessor { executorProperties == null ? buildExecutorProperties(threadPoolId, newDynamicPoolExecutor) : executorProperties); - return newDynamicPoolExecutor; } @@ -197,7 +187,6 @@ public final class DynamicThreadPoolPostProcessor implements BeanPostProcessor { String queueType = queue.getClass().getSimpleName(); int remainingCapacity = queue.remainingCapacity(); int queueCapacity = queueSize + remainingCapacity; - executorProperties.setCorePoolSize(executor.getCorePoolSize()) .setMaximumPoolSize(executor.getMaximumPoolSize()) .setAllowCoreThreadTimeOut(executor.allowsCoreThreadTimeOut()) @@ -207,7 +196,6 @@ public final class DynamicThreadPoolPostProcessor implements BeanPostProcessor { .setQueueCapacity(queueCapacity) .setRejectedHandler(((DynamicThreadPoolExecutor) executor).getRedundancyHandler().getClass().getSimpleName()) .setThreadPoolId(threadPoolId); - return executorProperties; } }