Code formatting, delete extra blank lines

pull/209/head
chen.ma 3 years ago
parent fe42a7e532
commit 1f3358375a

@ -85,7 +85,6 @@ public class DynamicThreadPoolExecutor extends AbstractDynamicExecutorSupport {
if (taskDecorator != null) { if (taskDecorator != null) {
command = taskDecorator.decorate(command); command = taskDecorator.decorate(command);
} }
super.execute(command); super.execute(command);
} }
@ -94,7 +93,6 @@ public class DynamicThreadPoolExecutor extends AbstractDynamicExecutorSupport {
if (executeTimeOut == null || executeTimeOut <= 0) { if (executeTimeOut == null || executeTimeOut <= 0) {
return; return;
} }
this.startTime.set(SystemClock.now()); this.startTime.set(SystemClock.now());
} }
@ -103,7 +101,6 @@ public class DynamicThreadPoolExecutor extends AbstractDynamicExecutorSupport {
if (executeTimeOut == null || executeTimeOut <= 0) { if (executeTimeOut == null || executeTimeOut <= 0) {
return; return;
} }
try { try {
long startTime = this.startTime.get(); long startTime = this.startTime.get();
long endTime = SystemClock.now(); long endTime = SystemClock.now();
@ -125,13 +122,7 @@ public class DynamicThreadPoolExecutor extends AbstractDynamicExecutorSupport {
return this; return this;
} }
/**
* Get reject count.
*
* @return
*/
public Long getRejectCountNum() { public Long getRejectCountNum() {
return rejectCount.get(); return rejectCount.get();
} }
} }

@ -230,5 +230,4 @@ public class AbstractBuildThreadPoolTemplate {
.build(); .build();
} }
} }
} }

@ -123,6 +123,8 @@ public class ThreadPoolBuilder implements Builder<ThreadPoolExecutor> {
*/ */
private Boolean allowCoreThreadTimeOut = false; private Boolean allowCoreThreadTimeOut = false;
private Boolean prestartCoreThread = false;
/** /**
* CPU / (1 - 0.8) * CPU / (1 - 0.8)
* *

@ -65,7 +65,7 @@ public final class DynamicThreadPoolPostProcessor implements BeanPostProcessor {
try { try {
dynamicThreadPool = ApplicationContextHolder.findAnnotationOnBean(beanName, DynamicThreadPool.class); dynamicThreadPool = ApplicationContextHolder.findAnnotationOnBean(beanName, DynamicThreadPool.class);
if (Objects.isNull(dynamicThreadPool)) { if (Objects.isNull(dynamicThreadPool)) {
// 适配低版本 SpringBoot // Adapt to lower versions of SpringBoot.
dynamicThreadPool = DynamicThreadPoolAnnotationUtil.findAnnotationOnBean(beanName, DynamicThreadPool.class); dynamicThreadPool = DynamicThreadPoolAnnotationUtil.findAnnotationOnBean(beanName, DynamicThreadPool.class);
if (Objects.isNull(dynamicThreadPool)) { if (Objects.isNull(dynamicThreadPool)) {
return bean; return bean;
@ -75,18 +75,15 @@ public final class DynamicThreadPoolPostProcessor implements BeanPostProcessor {
log.error("Failed to create dynamic thread pool in annotation mode.", ex); log.error("Failed to create dynamic thread pool in annotation mode.", ex);
return bean; return bean;
} }
DynamicThreadPoolExecutor dynamicExecutor = (DynamicThreadPoolExecutor) bean; DynamicThreadPoolExecutor dynamicExecutor = (DynamicThreadPoolExecutor) bean;
DynamicThreadPoolWrapper wrap = new DynamicThreadPoolWrapper(dynamicExecutor.getThreadPoolId(), dynamicExecutor); DynamicThreadPoolWrapper wrap = new DynamicThreadPoolWrapper(dynamicExecutor.getThreadPoolId(), dynamicExecutor);
ThreadPoolExecutor remoteExecutor = fillPoolAndRegister(wrap); ThreadPoolExecutor remoteExecutor = fillPoolAndRegister(wrap);
return remoteExecutor; return remoteExecutor;
} }
if (bean instanceof DynamicThreadPoolWrapper) { if (bean instanceof DynamicThreadPoolWrapper) {
DynamicThreadPoolWrapper wrap = (DynamicThreadPoolWrapper) bean; DynamicThreadPoolWrapper wrap = (DynamicThreadPoolWrapper) bean;
registerAndSubscribe(wrap); registerAndSubscribe(wrap);
} }
return bean; return bean;
} }
@ -143,20 +140,15 @@ public final class DynamicThreadPoolPostProcessor implements BeanPostProcessor {
// 设置动态线程池增强参数 // 设置动态线程池增强参数
ThreadPoolNotifyAlarm notify = Optional.ofNullable(executorProperties).map(ExecutorProperties::getNotify).orElse(null); ThreadPoolNotifyAlarm notify = Optional.ofNullable(executorProperties).map(ExecutorProperties::getNotify).orElse(null);
boolean isAlarm = Optional.ofNullable(notify) boolean isAlarm = Optional.ofNullable(notify)
.map(each -> each.getIsAlarm()) .map(each -> each.getIsAlarm()).orElseGet(() -> bootstrapCoreProperties.getAlarm() != null ? bootstrapCoreProperties.getAlarm() : true);
.orElseGet(() -> bootstrapCoreProperties.getAlarm() != null ? bootstrapCoreProperties.getAlarm() : true);
int activeAlarm = Optional.ofNullable(notify) int activeAlarm = Optional.ofNullable(notify)
.map(each -> each.getActiveAlarm()) .map(each -> each.getActiveAlarm()).orElseGet(() -> bootstrapCoreProperties.getActiveAlarm() != null ? bootstrapCoreProperties.getActiveAlarm() : 80);
.orElseGet(() -> bootstrapCoreProperties.getActiveAlarm() != null ? bootstrapCoreProperties.getActiveAlarm() : 80);
int capacityAlarm = Optional.ofNullable(notify) int capacityAlarm = Optional.ofNullable(notify)
.map(each -> each.getActiveAlarm()) .map(each -> each.getActiveAlarm()).orElseGet(() -> bootstrapCoreProperties.getCapacityAlarm() != null ? bootstrapCoreProperties.getCapacityAlarm() : 80);
.orElseGet(() -> bootstrapCoreProperties.getCapacityAlarm() != null ? bootstrapCoreProperties.getCapacityAlarm() : 80);
int interval = Optional.ofNullable(notify) int interval = Optional.ofNullable(notify)
.map(each -> each.getInterval()) .map(each -> each.getInterval()).orElseGet(() -> bootstrapCoreProperties.getAlarmInterval() != null ? bootstrapCoreProperties.getAlarmInterval() : 5);
.orElseGet(() -> bootstrapCoreProperties.getAlarmInterval() != null ? bootstrapCoreProperties.getAlarmInterval() : 5);
String receive = Optional.ofNullable(notify) String receive = Optional.ofNullable(notify)
.map(each -> each.getReceive()) .map(each -> each.getReceive()).orElseGet(() -> bootstrapCoreProperties.getReceive() != null ? bootstrapCoreProperties.getReceive() : null);
.orElseGet(() -> bootstrapCoreProperties.getReceive() != null ? bootstrapCoreProperties.getReceive() : null);
ThreadPoolNotifyAlarm threadPoolNotifyAlarm = new ThreadPoolNotifyAlarm(isAlarm, activeAlarm, capacityAlarm); ThreadPoolNotifyAlarm threadPoolNotifyAlarm = new ThreadPoolNotifyAlarm(isAlarm, activeAlarm, capacityAlarm);
threadPoolNotifyAlarm.setInterval(interval); threadPoolNotifyAlarm.setInterval(interval);
threadPoolNotifyAlarm.setReceive(receive); threadPoolNotifyAlarm.setReceive(receive);
@ -169,7 +161,6 @@ public final class DynamicThreadPoolPostProcessor implements BeanPostProcessor {
boolean waitForTasksToCompleteOnShutdown = ((DynamicThreadPoolExecutor) dynamicThreadPoolWrap.getExecutor()).waitForTasksToCompleteOnShutdown; boolean waitForTasksToCompleteOnShutdown = ((DynamicThreadPoolExecutor) dynamicThreadPoolWrap.getExecutor()).waitForTasksToCompleteOnShutdown;
((DynamicThreadPoolExecutor) newDynamicPoolExecutor).setSupportParam(awaitTerminationMillis, waitForTasksToCompleteOnShutdown); ((DynamicThreadPoolExecutor) newDynamicPoolExecutor).setSupportParam(awaitTerminationMillis, waitForTasksToCompleteOnShutdown);
} }
dynamicThreadPoolWrap.setExecutor(newDynamicPoolExecutor); dynamicThreadPoolWrap.setExecutor(newDynamicPoolExecutor);
} }
@ -179,7 +170,6 @@ public final class DynamicThreadPoolPostProcessor implements BeanPostProcessor {
executorProperties == null executorProperties == null
? buildExecutorProperties(threadPoolId, newDynamicPoolExecutor) ? buildExecutorProperties(threadPoolId, newDynamicPoolExecutor)
: executorProperties); : executorProperties);
return newDynamicPoolExecutor; return newDynamicPoolExecutor;
} }
@ -197,7 +187,6 @@ public final class DynamicThreadPoolPostProcessor implements BeanPostProcessor {
String queueType = queue.getClass().getSimpleName(); String queueType = queue.getClass().getSimpleName();
int remainingCapacity = queue.remainingCapacity(); int remainingCapacity = queue.remainingCapacity();
int queueCapacity = queueSize + remainingCapacity; int queueCapacity = queueSize + remainingCapacity;
executorProperties.setCorePoolSize(executor.getCorePoolSize()) executorProperties.setCorePoolSize(executor.getCorePoolSize())
.setMaximumPoolSize(executor.getMaximumPoolSize()) .setMaximumPoolSize(executor.getMaximumPoolSize())
.setAllowCoreThreadTimeOut(executor.allowsCoreThreadTimeOut()) .setAllowCoreThreadTimeOut(executor.allowsCoreThreadTimeOut())
@ -207,7 +196,6 @@ public final class DynamicThreadPoolPostProcessor implements BeanPostProcessor {
.setQueueCapacity(queueCapacity) .setQueueCapacity(queueCapacity)
.setRejectedHandler(((DynamicThreadPoolExecutor) executor).getRedundancyHandler().getClass().getSimpleName()) .setRejectedHandler(((DynamicThreadPoolExecutor) executor).getRedundancyHandler().getClass().getSimpleName())
.setThreadPoolId(threadPoolId); .setThreadPoolId(threadPoolId);
return executorProperties; return executorProperties;
} }
} }

Loading…
Cancel
Save