This is an automated email from the ASF dual-hosted git repository. lihan pushed a commit to branch 8.5.x in repository https://gitbox.apache.org/repos/asf/tomcat.git
The following commit(s) were added to refs/heads/8.5.x by this push: new 4aeddee4cf Polishing TaskQueue & ThreadPoolExecutor 4aeddee4cf is described below commit 4aeddee4cf9829ac313f68c7656eff80c26cee0c 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-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org