diff --git a/hawkbit-autoconfigure/src/main/java/org/eclipse/hawkbit/autoconfigure/scheduling/AsyncConfigurerAutoConfiguration.java b/hawkbit-autoconfigure/src/main/java/org/eclipse/hawkbit/autoconfigure/scheduling/AsyncConfigurerAutoConfiguration.java index f3aa7e729..5b9e9894a 100644 --- a/hawkbit-autoconfigure/src/main/java/org/eclipse/hawkbit/autoconfigure/scheduling/AsyncConfigurerAutoConfiguration.java +++ b/hawkbit-autoconfigure/src/main/java/org/eclipse/hawkbit/autoconfigure/scheduling/AsyncConfigurerAutoConfiguration.java @@ -13,7 +13,6 @@ import java.util.concurrent.Executor; import org.springframework.aop.interceptor.AsyncUncaughtExceptionHandler; import org.springframework.aop.interceptor.SimpleAsyncUncaughtExceptionHandler; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; import org.springframework.context.annotation.Configuration; @@ -28,9 +27,11 @@ import org.springframework.scheduling.annotation.EnableAsync; @ConditionalOnMissingBean(AsyncConfigurer.class) public class AsyncConfigurerAutoConfiguration implements AsyncConfigurer { - @Autowired - @Qualifier("asyncExecutor") - private Executor executor; + private final Executor executor; + + public AsyncConfigurerAutoConfiguration(@Qualifier("asyncExecutor") final Executor executor) { + this.executor = executor; + } @Override public Executor getAsyncExecutor() { @@ -41,5 +42,4 @@ public class AsyncConfigurerAutoConfiguration implements AsyncConfigurer { public AsyncUncaughtExceptionHandler getAsyncUncaughtExceptionHandler() { return new SimpleAsyncUncaughtExceptionHandler(); } - -} +} \ No newline at end of file diff --git a/hawkbit-autoconfigure/src/main/java/org/eclipse/hawkbit/autoconfigure/scheduling/AsyncConfigurerThreadPoolProperties.java b/hawkbit-autoconfigure/src/main/java/org/eclipse/hawkbit/autoconfigure/scheduling/AsyncConfigurerThreadPoolProperties.java new file mode 100644 index 000000000..02e5e2e73 --- /dev/null +++ b/hawkbit-autoconfigure/src/main/java/org/eclipse/hawkbit/autoconfigure/scheduling/AsyncConfigurerThreadPoolProperties.java @@ -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; +} diff --git a/hawkbit-autoconfigure/src/main/java/org/eclipse/hawkbit/autoconfigure/scheduling/AsyncConfigurerThreadpoolProperties.java b/hawkbit-autoconfigure/src/main/java/org/eclipse/hawkbit/autoconfigure/scheduling/AsyncConfigurerThreadpoolProperties.java deleted file mode 100644 index 221d80d70..000000000 --- a/hawkbit-autoconfigure/src/main/java/org/eclipse/hawkbit/autoconfigure/scheduling/AsyncConfigurerThreadpoolProperties.java +++ /dev/null @@ -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; - } - -} diff --git a/hawkbit-autoconfigure/src/main/java/org/eclipse/hawkbit/autoconfigure/scheduling/ExecutorAutoConfiguration.java b/hawkbit-autoconfigure/src/main/java/org/eclipse/hawkbit/autoconfigure/scheduling/ExecutorAutoConfiguration.java index c3a03dcc5..9665cef39 100644 --- a/hawkbit-autoconfigure/src/main/java/org/eclipse/hawkbit/autoconfigure/scheduling/ExecutorAutoConfiguration.java +++ b/hawkbit-autoconfigure/src/main/java/org/eclipse/hawkbit/autoconfigure/scheduling/ExecutorAutoConfiguration.java @@ -12,7 +12,6 @@ package org.eclipse.hawkbit.autoconfigure.scheduling; import java.util.Locale; import java.util.concurrent.ArrayBlockingQueue; import java.util.concurrent.BlockingQueue; -import java.util.concurrent.Executor; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.concurrent.ScheduledExecutorService; @@ -23,7 +22,6 @@ import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicLong; import lombok.extern.slf4j.Slf4j; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; import org.springframework.boot.context.properties.EnableConfigurationProperties; 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.concurrent.ConcurrentTaskExecutor; import org.springframework.scheduling.concurrent.ConcurrentTaskScheduler; -import org.springframework.security.concurrent.DelegatingSecurityContextExecutor; import org.springframework.security.concurrent.DelegatingSecurityContextExecutorService; import org.springframework.security.concurrent.DelegatingSecurityContextScheduledExecutorService; @@ -41,15 +38,17 @@ import org.springframework.security.concurrent.DelegatingSecurityContextSchedule */ @Slf4j @Configuration -@EnableConfigurationProperties(AsyncConfigurerThreadpoolProperties.class) +@EnableConfigurationProperties(AsyncConfigurerThreadPoolProperties.class) public class ExecutorAutoConfiguration { - @Autowired - private AsyncConfigurerThreadpoolProperties asyncConfigurerProperties; + private final AsyncConfigurerThreadPoolProperties asyncConfigurerProperties; + + public ExecutorAutoConfiguration(final AsyncConfigurerThreadPoolProperties asyncConfigurerProperties) { + this.asyncConfigurerProperties = asyncConfigurerProperties; + } /** - * @return ExecutorService with security context availability in thread - * execution. + * @return ExecutorService with security context availability in thread execution. */ @Bean(destroyMethod = "shutdown") @ConditionalOnMissingBean @@ -67,28 +66,13 @@ public class ExecutorAutoConfiguration { } /** - * @return the executor for UI background processes. - */ - @Bean(name = "uiExecutor") - @ConditionalOnMissingBean(name = "uiExecutor") - public Executor uiExecutor() { - final BlockingQueue 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. + * @return {@link ScheduledExecutorService} with security context availability in thread execution. */ @Bean(destroyMethod = "shutdown") @ConditionalOnMissingBean public ScheduledExecutorService scheduledExecutorService() { - return new DelegatingSecurityContextScheduledExecutorService( - Executors.newScheduledThreadPool(asyncConfigurerProperties.getSchedulerThreads(), - threadFactory("central-scheduled-executor-pool-%d"))); + return new DelegatingSecurityContextScheduledExecutorService(Executors.newScheduledThreadPool( + asyncConfigurerProperties.getSchedulerThreads(), threadFactory("central-scheduled-executor-pool-%d"))); } /** @@ -110,14 +94,12 @@ public class ExecutorAutoConfiguration { } /** - * @return central ThreadPoolExecutor for general purpose multi threaded - * operations. Tries an orderly shutdown when destroyed. + * @return central ThreadPoolExecutor for general purpose multithreaded operations. Tries an orderly shutdown when destroyed. */ private ThreadPoolExecutor threadPoolExecutor() { - final BlockingQueue blockingQueue = new ArrayBlockingQueue<>( - asyncConfigurerProperties.getQueuesize()); - return new ThreadPoolExecutor(asyncConfigurerProperties.getCorethreads(), - asyncConfigurerProperties.getMaxthreads(), asyncConfigurerProperties.getIdletimeout(), + final BlockingQueue blockingQueue = new ArrayBlockingQueue<>(asyncConfigurerProperties.getQueueSize()); + return new ThreadPoolExecutor(asyncConfigurerProperties.getCoreThreads(), + asyncConfigurerProperties.getMaxThreads(), asyncConfigurerProperties.getIdleTimeout(), TimeUnit.MILLISECONDS, blockingQueue, threadFactory("central-executor-pool-%d"), new PoolSizeExceededPolicy()); @@ -133,4 +115,4 @@ public class ExecutorAutoConfiguration { super.rejectedExecution(r, executor); } } -} +} \ No newline at end of file