This is an automated email from the ASF dual-hosted git repository.
remm pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/tomcat.git
The following commit(s) were added to refs/heads/main by this push:
new 5d8fb49d2d Add thread idle time configuration
5d8fb49d2d is described below
commit 5d8fb49d2db63f37e3bb322f1c08a98ae287a8e7
Author: remm <[email protected]>
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 4c9942a3b4..006e8925ef 100644
--- a/java/org/apache/tomcat/util/net/AbstractEndpoint.java
+++ b/java/org/apache/tomcat/util/net/AbstractEndpoint.java
@@ -975,6 +975,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 96cd91a95b..4f3e7a605d 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 1311af1eb5..c0636f5559 100644
--- a/webapps/docs/config/http.xml
+++ b/webapps/docs/config/http.xml
@@ -682,6 +682,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: [email protected]
For additional commands, e-mail: [email protected]