Remove ExecutorAutoConfiguration.uiExecutor (#2001)

Signed-off-by: Avgustin Marinov <Avgustin.Marinov@bosch.com>
This commit is contained in:
Avgustin Marinov
2024-11-11 13:17:55 +02:00
committed by GitHub
parent 1a741bcdb1
commit f223ebf3a8
4 changed files with 68 additions and 125 deletions

View File

@@ -13,7 +13,6 @@ import java.util.concurrent.Executor;
import org.springframework.aop.interceptor.AsyncUncaughtExceptionHandler; import org.springframework.aop.interceptor.AsyncUncaughtExceptionHandler;
import org.springframework.aop.interceptor.SimpleAsyncUncaughtExceptionHandler; import org.springframework.aop.interceptor.SimpleAsyncUncaughtExceptionHandler;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
@@ -28,9 +27,11 @@ import org.springframework.scheduling.annotation.EnableAsync;
@ConditionalOnMissingBean(AsyncConfigurer.class) @ConditionalOnMissingBean(AsyncConfigurer.class)
public class AsyncConfigurerAutoConfiguration implements AsyncConfigurer { public class AsyncConfigurerAutoConfiguration implements AsyncConfigurer {
@Autowired private final Executor executor;
@Qualifier("asyncExecutor")
private Executor executor; public AsyncConfigurerAutoConfiguration(@Qualifier("asyncExecutor") final Executor executor) {
this.executor = executor;
}
@Override @Override
public Executor getAsyncExecutor() { public Executor getAsyncExecutor() {
@@ -41,5 +42,4 @@ public class AsyncConfigurerAutoConfiguration implements AsyncConfigurer {
public AsyncUncaughtExceptionHandler getAsyncUncaughtExceptionHandler() { public AsyncUncaughtExceptionHandler getAsyncUncaughtExceptionHandler() {
return new SimpleAsyncUncaughtExceptionHandler(); return new SimpleAsyncUncaughtExceptionHandler();
} }
}
}

View File

@@ -0,0 +1,47 @@
/**
* Copyright (c) 2015 Bosch Software Innovations GmbH and others
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.eclipse.hawkbit.autoconfigure.scheduling;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
/**
* Properties for the async configurer.
*/
@Data
@ConfigurationProperties("hawkbit.threadpool")
public class AsyncConfigurerThreadPoolProperties {
/**
* Max queue size for central event executor.
*/
private Integer queueSize = 5_000;
/**
* Core processing threads for central event executor.
*/
private Integer coreThreads = 5;
/**
* Maximum thread pool size for central event executor.
*/
private Integer maxThreads = 20;
/**
* Core processing threads for scheduled event executor.
*/
private Integer schedulerThreads = 3;
/**
* When the number of threads is greater than the core, this is the maximum
* time that excess idle threads will wait for new tasks before terminating.
*/
private Long idleTimeout = 10000L;
}

View File

@@ -1,86 +0,0 @@
/**
* Copyright (c) 2015 Bosch Software Innovations GmbH and others
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.eclipse.hawkbit.autoconfigure.scheduling;
import org.springframework.boot.context.properties.ConfigurationProperties;
/**
* Properties for the async configurer.
*/
@ConfigurationProperties("hawkbit.threadpool")
public class AsyncConfigurerThreadpoolProperties {
/**
* Max queue size for central event executor.
*/
private Integer queuesize = 5_000;
/**
* Core processing threads for central event executor.
*/
private Integer corethreads = 5;
/**
* Maximum thread pool size for central event executor.
*/
private Integer maxthreads = 20;
/**
* Core processing threads for scheduled event executor.
*/
private Integer schedulerThreads = 3;
/**
* When the number of threads is greater than the core, this is the maximum
* time that excess idle threads will wait for new tasks before terminating.
*/
private Long idletimeout = 10000L;
public Integer getQueuesize() {
return queuesize;
}
public void setQueuesize(final Integer queuesize) {
this.queuesize = queuesize;
}
public Integer getCorethreads() {
return corethreads;
}
public void setCorethreads(final Integer corethreads) {
this.corethreads = corethreads;
}
public Integer getMaxthreads() {
return maxthreads;
}
public void setMaxthreads(final Integer maxthreads) {
this.maxthreads = maxthreads;
}
public Long getIdletimeout() {
return idletimeout;
}
public void setIdletimeout(final Long idletimeout) {
this.idletimeout = idletimeout;
}
public Integer getSchedulerThreads() {
return schedulerThreads;
}
public void setSchedulerThreads(final Integer schedulerThreads) {
this.schedulerThreads = schedulerThreads;
}
}

View File

@@ -12,7 +12,6 @@ package org.eclipse.hawkbit.autoconfigure.scheduling;
import java.util.Locale; import java.util.Locale;
import java.util.concurrent.ArrayBlockingQueue; import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.BlockingQueue; import java.util.concurrent.BlockingQueue;
import java.util.concurrent.Executor;
import java.util.concurrent.ExecutorService; import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors; import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.ScheduledExecutorService;
@@ -23,7 +22,6 @@ import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicLong; import java.util.concurrent.atomic.AtomicLong;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
@@ -32,7 +30,6 @@ import org.springframework.core.task.TaskExecutor;
import org.springframework.scheduling.TaskScheduler; import org.springframework.scheduling.TaskScheduler;
import org.springframework.scheduling.concurrent.ConcurrentTaskExecutor; import org.springframework.scheduling.concurrent.ConcurrentTaskExecutor;
import org.springframework.scheduling.concurrent.ConcurrentTaskScheduler; import org.springframework.scheduling.concurrent.ConcurrentTaskScheduler;
import org.springframework.security.concurrent.DelegatingSecurityContextExecutor;
import org.springframework.security.concurrent.DelegatingSecurityContextExecutorService; import org.springframework.security.concurrent.DelegatingSecurityContextExecutorService;
import org.springframework.security.concurrent.DelegatingSecurityContextScheduledExecutorService; import org.springframework.security.concurrent.DelegatingSecurityContextScheduledExecutorService;
@@ -41,15 +38,17 @@ import org.springframework.security.concurrent.DelegatingSecurityContextSchedule
*/ */
@Slf4j @Slf4j
@Configuration @Configuration
@EnableConfigurationProperties(AsyncConfigurerThreadpoolProperties.class) @EnableConfigurationProperties(AsyncConfigurerThreadPoolProperties.class)
public class ExecutorAutoConfiguration { public class ExecutorAutoConfiguration {
@Autowired private final AsyncConfigurerThreadPoolProperties asyncConfigurerProperties;
private AsyncConfigurerThreadpoolProperties asyncConfigurerProperties;
public ExecutorAutoConfiguration(final AsyncConfigurerThreadPoolProperties asyncConfigurerProperties) {
this.asyncConfigurerProperties = asyncConfigurerProperties;
}
/** /**
* @return ExecutorService with security context availability in thread * @return ExecutorService with security context availability in thread execution.
* execution.
*/ */
@Bean(destroyMethod = "shutdown") @Bean(destroyMethod = "shutdown")
@ConditionalOnMissingBean @ConditionalOnMissingBean
@@ -67,28 +66,13 @@ public class ExecutorAutoConfiguration {
} }
/** /**
* @return the executor for UI background processes. * @return {@link ScheduledExecutorService} with security context availability in thread execution.
*/
@Bean(name = "uiExecutor")
@ConditionalOnMissingBean(name = "uiExecutor")
public Executor uiExecutor() {
final BlockingQueue<Runnable> blockingQueue = new ArrayBlockingQueue<>(20);
final ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor(1, 20, 10000, TimeUnit.MILLISECONDS,
blockingQueue, threadFactory("ui-executor-pool-%d"));
threadPoolExecutor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
return new DelegatingSecurityContextExecutor(threadPoolExecutor);
}
/**
* @return {@link ScheduledExecutorService} with security context
* availability in thread execution.
*/ */
@Bean(destroyMethod = "shutdown") @Bean(destroyMethod = "shutdown")
@ConditionalOnMissingBean @ConditionalOnMissingBean
public ScheduledExecutorService scheduledExecutorService() { public ScheduledExecutorService scheduledExecutorService() {
return new DelegatingSecurityContextScheduledExecutorService( return new DelegatingSecurityContextScheduledExecutorService(Executors.newScheduledThreadPool(
Executors.newScheduledThreadPool(asyncConfigurerProperties.getSchedulerThreads(), asyncConfigurerProperties.getSchedulerThreads(), threadFactory("central-scheduled-executor-pool-%d")));
threadFactory("central-scheduled-executor-pool-%d")));
} }
/** /**
@@ -110,14 +94,12 @@ public class ExecutorAutoConfiguration {
} }
/** /**
* @return central ThreadPoolExecutor for general purpose multi threaded * @return central ThreadPoolExecutor for general purpose multithreaded operations. Tries an orderly shutdown when destroyed.
* operations. Tries an orderly shutdown when destroyed.
*/ */
private ThreadPoolExecutor threadPoolExecutor() { private ThreadPoolExecutor threadPoolExecutor() {
final BlockingQueue<Runnable> blockingQueue = new ArrayBlockingQueue<>( final BlockingQueue<Runnable> blockingQueue = new ArrayBlockingQueue<>(asyncConfigurerProperties.getQueueSize());
asyncConfigurerProperties.getQueuesize()); return new ThreadPoolExecutor(asyncConfigurerProperties.getCoreThreads(),
return new ThreadPoolExecutor(asyncConfigurerProperties.getCorethreads(), asyncConfigurerProperties.getMaxThreads(), asyncConfigurerProperties.getIdleTimeout(),
asyncConfigurerProperties.getMaxthreads(), asyncConfigurerProperties.getIdletimeout(),
TimeUnit.MILLISECONDS, blockingQueue, TimeUnit.MILLISECONDS, blockingQueue,
threadFactory("central-executor-pool-%d"), threadFactory("central-executor-pool-%d"),
new PoolSizeExceededPolicy()); new PoolSizeExceededPolicy());
@@ -133,4 +115,4 @@ public class ExecutorAutoConfiguration {
super.rejectedExecution(r, executor); super.rejectedExecution(r, executor);
} }
} }
} }