This is an automated email from the ASF dual-hosted git repository. remm pushed a commit to branch 9.0.x in repository https://gitbox.apache.org/repos/asf/tomcat.git
commit bc5425ef8788cb52fe31ef040c07fb8efff12e7f Author: remm <r...@apache.org> AuthorDate: Tue Mar 12 20:38:11 2024 +0100 Add thread idle time configuration The default remains 60s. --- .../apache/tomcat/util/net/AbstractEndpoint.java | 24 ++++++++++++++++++++++ webapps/docs/changelog.xml | 10 +++++++++ webapps/docs/config/http.xml | 13 ++++++++++++ 3 files changed, 47 insertions(+) diff --git a/java/org/apache/tomcat/util/net/AbstractEndpoint.java b/java/org/apache/tomcat/util/net/AbstractEndpoint.java index 05a1ede2ec..7396154b53 100644 --- a/java/org/apache/tomcat/util/net/AbstractEndpoint.java +++ b/java/org/apache/tomcat/util/net/AbstractEndpoint.java @@ -875,6 +875,30 @@ public abstract class AbstractEndpoint<S,U> { } + /** + * Amount of time in milliseconds before the internal thread pool stops any idle threads + * if the amount of thread is greater than the minimum amount of spare threads. + */ + private int threadsMaxIdleTime = 60000; + public void setThreadsMaxIdleTime(int threadsMaxIdleTime) { + this.threadsMaxIdleTime = threadsMaxIdleTime; + Executor executor = this.executor; + if (internalExecutor && executor instanceof ThreadPoolExecutor) { + // The internal executor should always be an instance of + // org.apache.tomcat.util.threads.ThreadPoolExecutor but it may be + // null if the endpoint is not running. + // This check also avoids various threading issues. + ((ThreadPoolExecutor) executor).setKeepAliveTime(threadsMaxIdleTime, TimeUnit.MILLISECONDS); + } + } + public int getThreadsMaxIdleTime() { + if (internalExecutor) { + return threadsMaxIdleTime; + } else { + return -1; + } + } + /** * Priority of the worker threads. */ diff --git a/webapps/docs/changelog.xml b/webapps/docs/changelog.xml index 825e6634b9..b49bdc64fe 100644 --- a/webapps/docs/changelog.xml +++ b/webapps/docs/changelog.xml @@ -120,6 +120,16 @@ </add> </changelog> </subsection> + <subsection name="Catalina"> + <changelog> + <fix> + Add <code>threadsMaxIdleTime</code> attribute to the endpoint, + to allow configuring the amount of time before an internal executor + will scale back to the configured <code>minSpareThreads</code> size. + (remm) + </fix> + </changelog> + </subsection> <subsection name="Jasper"> <changelog> <fix> diff --git a/webapps/docs/config/http.xml b/webapps/docs/config/http.xml index 415aef54a3..253fed0314 100644 --- a/webapps/docs/config/http.xml +++ b/webapps/docs/config/http.xml @@ -726,6 +726,19 @@ <code>-1</code> to make clear that it is not used.</p> </attribute> + <attribute name="threadsMaxIdleTime" required="false"> + <p>The amount of time in milliseconds that threads will be kept alive by + the thread pool, if there are more than <code>minSpareThreads</code> + threads in the executor. If not specified, the default of + <code>60000</code> milliseconds is used. If an executor is associated + with this connector, this attribute + is ignored as the connector will execute tasks using the executor rather + than an internal thread pool. Note that if an executor is configured any + value set for this attribute will be recorded correctly but it will be + reported (e.g. via JMX) as <code>-1</code> to make clear that it is not + used.</p> + </attribute> + <attribute name="throwOnFailure" required="false"> <p>If the Connector experiences an Exception during a Lifecycle transition should the Exception be rethrown or logged? If not specified, the default --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org