diff --git a/spring-context/src/main/java/org/springframework/scheduling/annotation/SchedulingConfigurer.java b/spring-context/src/main/java/org/springframework/scheduling/annotation/SchedulingConfigurer.java index 26f0076077f..7ad039fb8dd 100644 --- a/spring-context/src/main/java/org/springframework/scheduling/annotation/SchedulingConfigurer.java +++ b/spring-context/src/main/java/org/springframework/scheduling/annotation/SchedulingConfigurer.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2021 the original author or authors. + * Copyright 2002-2023 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -40,10 +40,10 @@ import org.springframework.scheduling.config.ScheduledTaskRegistrar; public interface SchedulingConfigurer { /** - * Callback allowing a {@link org.springframework.scheduling.TaskScheduler - * TaskScheduler} and specific {@link org.springframework.scheduling.config.Task Task} - * instances to be registered against the given the {@link ScheduledTaskRegistrar}. - * @param taskRegistrar the registrar to be configured. + * Callback allowing a {@link org.springframework.scheduling.TaskScheduler} + * and specific {@link org.springframework.scheduling.config.Task} instances + * to be registered against the given the {@link ScheduledTaskRegistrar}. + * @param taskRegistrar the registrar to be configured */ void configureTasks(ScheduledTaskRegistrar taskRegistrar); diff --git a/spring-core/src/main/java/org/springframework/core/task/SimpleAsyncTaskExecutor.java b/spring-core/src/main/java/org/springframework/core/task/SimpleAsyncTaskExecutor.java index 072502a868c..8540697a52b 100644 --- a/spring-core/src/main/java/org/springframework/core/task/SimpleAsyncTaskExecutor.java +++ b/spring-core/src/main/java/org/springframework/core/task/SimpleAsyncTaskExecutor.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2022 the original author or authors. + * Copyright 2002-2023 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -33,8 +33,8 @@ import org.springframework.util.concurrent.ListenableFutureTask; * {@link TaskExecutor} implementation that fires up a new Thread for each task, * executing it asynchronously. * - *

Supports limiting concurrent threads through the "concurrencyLimit" - * bean property. By default, the number of concurrent threads is unlimited. + *

Supports limiting concurrent threads through {@link #setConcurrencyLimit}. + * By default, the number of concurrent task executions is unlimited. * *

NOTE: This implementation does not reuse threads! Consider a * thread-pooling TaskExecutor implementation instead, in particular for @@ -133,33 +133,31 @@ public class SimpleAsyncTaskExecutor extends CustomizableThreadCreator * have to cast it and call {@code Future#get} to evaluate exceptions. * @since 4.3 */ - public final void setTaskDecorator(TaskDecorator taskDecorator) { + public void setTaskDecorator(TaskDecorator taskDecorator) { this.taskDecorator = taskDecorator; } /** - * Set the maximum number of parallel accesses allowed. - * -1 indicates no concurrency limit at all. - *

In principle, this limit can be changed at runtime, - * although it is generally designed as a config time setting. - * NOTE: Do not switch between -1 and any concrete limit at runtime, - * as this will lead to inconsistent concurrency counts: A limit - * of -1 effectively turns off concurrency counting completely. + * Set the maximum number of parallel task executions allowed. + * The default of -1 indicates no concurrency limit at all. + *

This is the equivalent of a maximum pool size in a thread pool, + * preventing temporary overload of the thread management system. * @see #UNBOUNDED_CONCURRENCY + * @see org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor#setMaxPoolSize */ public void setConcurrencyLimit(int concurrencyLimit) { this.concurrencyThrottle.setConcurrencyLimit(concurrencyLimit); } /** - * Return the maximum number of parallel accesses allowed. + * Return the maximum number of parallel task executions allowed. */ public final int getConcurrencyLimit() { return this.concurrencyThrottle.getConcurrencyLimit(); } /** - * Return whether this throttle is currently active. + * Return whether the concurrency throttle is currently active. * @return {@code true} if the concurrency limit for this instance is active * @see #getConcurrencyLimit() * @see #setConcurrencyLimit diff --git a/spring-core/src/main/java/org/springframework/util/ConcurrencyThrottleSupport.java b/spring-core/src/main/java/org/springframework/util/ConcurrencyThrottleSupport.java index 6d7d272b4fd..370537bf9a3 100644 --- a/spring-core/src/main/java/org/springframework/util/ConcurrencyThrottleSupport.java +++ b/spring-core/src/main/java/org/springframework/util/ConcurrencyThrottleSupport.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2018 the original author or authors. + * Copyright 2002-2023 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -69,7 +69,7 @@ public abstract class ConcurrencyThrottleSupport implements Serializable { /** * Set the maximum number of concurrent access attempts allowed. - * -1 indicates unbounded concurrency. + * The default of -1 indicates no concurrency limit at all. *

In principle, this limit can be changed at runtime, * although it is generally designed as a config time setting. *

NOTE: Do not switch between -1 and any concrete limit at runtime, @@ -143,9 +143,10 @@ public abstract class ConcurrencyThrottleSupport implements Serializable { */ protected void afterAccess() { if (this.concurrencyLimit >= 0) { + boolean debug = logger.isDebugEnabled(); synchronized (this.monitor) { this.concurrencyCount--; - if (logger.isDebugEnabled()) { + if (debug) { logger.debug("Returning from throttle at concurrency count " + this.concurrencyCount); } this.monitor.notify();