You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by li...@apache.org on 2022/09/27 03:07:15 UTC
[tomcat] branch 9.0.x updated: Polishing TaskQueue & ThreadPoolExecutor
This is an automated email from the ASF dual-hosted git repository.
lihan pushed a commit to branch 9.0.x
in repository https://gitbox.apache.org/repos/asf/tomcat.git
The following commit(s) were added to refs/heads/9.0.x by this push:
new ef7e3d48a5 Polishing TaskQueue & ThreadPoolExecutor
ef7e3d48a5 is described below
commit ef7e3d48a58eb0bb7dd0693179e674ef1aab6772
Author: lihan <li...@apache.org>
AuthorDate: Tue Sep 27 11:04:44 2022 +0800
Polishing TaskQueue & ThreadPoolExecutor
The ThreadPoolExecutor#setCorePoolSize no longer does queue.remainingCapacity()==0 checks on JDK7 and above, so remove the code that temporarily fakes this condition.
---
java/org/apache/tomcat/util/threads/TaskQueue.java | 25 ----------------------
.../tomcat/util/threads/ThreadPoolExecutor.java | 13 -----------
2 files changed, 38 deletions(-)
diff --git a/java/org/apache/tomcat/util/threads/TaskQueue.java b/java/org/apache/tomcat/util/threads/TaskQueue.java
index 3ad5a2a587..cacb320d65 100644
--- a/java/org/apache/tomcat/util/threads/TaskQueue.java
+++ b/java/org/apache/tomcat/util/threads/TaskQueue.java
@@ -38,10 +38,6 @@ public class TaskQueue extends LinkedBlockingQueue<Runnable> {
private transient volatile ThreadPoolExecutor parent = null;
- // No need to be volatile. This is written and read in a single thread
- // (when stopping a context and firing the listeners)
- private int forcedRemainingCapacity = -1;
-
public TaskQueue() {
super();
}
@@ -145,25 +141,4 @@ public class TaskQueue extends LinkedBlockingQueue<Runnable> {
}
return super.take();
}
-
- @Override
- public int remainingCapacity() {
- if (forcedRemainingCapacity > DEFAULT_FORCED_REMAINING_CAPACITY) {
- // ThreadPoolExecutor.setCorePoolSize checks that
- // remainingCapacity==0 to allow to interrupt idle threads
- // I don't see why, but this hack allows to conform to this
- // "requirement"
- return forcedRemainingCapacity;
- }
- return super.remainingCapacity();
- }
-
- public void setForcedRemainingCapacity(int forcedRemainingCapacity) {
- this.forcedRemainingCapacity = forcedRemainingCapacity;
- }
-
- void resetForcedRemainingCapacity() {
- this.forcedRemainingCapacity = DEFAULT_FORCED_REMAINING_CAPACITY;
- }
-
}
diff --git a/java/org/apache/tomcat/util/threads/ThreadPoolExecutor.java b/java/org/apache/tomcat/util/threads/ThreadPoolExecutor.java
index d800cad534..df46be1853 100644
--- a/java/org/apache/tomcat/util/threads/ThreadPoolExecutor.java
+++ b/java/org/apache/tomcat/util/threads/ThreadPoolExecutor.java
@@ -1938,15 +1938,6 @@ public class ThreadPoolExecutor extends AbstractExecutorService {
// save the current pool parameters to restore them later
int savedCorePoolSize = this.getCorePoolSize();
- TaskQueue taskQueue =
- getQueue() instanceof TaskQueue ? (TaskQueue) getQueue() : null;
- if (taskQueue != null) {
- // note by slaurent : quite oddly threadPoolExecutor.setCorePoolSize
- // checks that queue.remainingCapacity()==0. I did not understand
- // why, but to get the intended effect of waking up idle threads, I
- // temporarily fake this condition.
- taskQueue.setForcedRemainingCapacity(0);
- }
// setCorePoolSize(0) wakes idle threads
this.setCorePoolSize(0);
@@ -1955,10 +1946,6 @@ public class ThreadPoolExecutor extends AbstractExecutorService {
// all threads of the pool are renewed in a limited time, something like
// (threadKeepAlive + longest request time)
- if (taskQueue != null) {
- // ok, restore the state of the queue and pool
- taskQueue.resetForcedRemainingCapacity();
- }
this.setCorePoolSize(savedCorePoolSize);
}
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org