This is an automated email from the ASF dual-hosted git repository.

mgrigorov 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 ad66248  Change forcedRemainingCapacity from Integer to int
ad66248 is described below

commit ad66248d551a707cc0df37773fb06ef0a35aa578
Author: Martin Tzvetanov Grigorov <mgrigo...@apache.org>
AuthorDate: Tue Aug 25 14:36:23 2020 +0300

    Change forcedRemainingCapacity from Integer to int
    
    No need to create object (or use Integer cache) and cast it to primitive 
int.
    'forcedRemainingCapacity' can do its job with a primitive int, since 
Queue's capacity cannot be negative value
---
 java/org/apache/tomcat/util/threads/TaskQueue.java        | 15 ++++++++++-----
 .../apache/tomcat/util/threads/ThreadPoolExecutor.java    |  4 ++--
 2 files changed, 12 insertions(+), 7 deletions(-)

diff --git a/java/org/apache/tomcat/util/threads/TaskQueue.java 
b/java/org/apache/tomcat/util/threads/TaskQueue.java
index 87c93a9..35f1d89 100644
--- a/java/org/apache/tomcat/util/threads/TaskQueue.java
+++ b/java/org/apache/tomcat/util/threads/TaskQueue.java
@@ -35,12 +35,13 @@ public class TaskQueue extends 
LinkedBlockingQueue<Runnable> {
     private static final long serialVersionUID = 1L;
     protected static final StringManager sm = StringManager
             .getManager("org.apache.tomcat.util.threads.res");
+    private static final int DEFAULT_FORCED_REMAINING_CAPACITY = -1;
 
     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 Integer forcedRemainingCapacity = null;
+    // (when stopping a context and firing the listeners)
+    private int forcedRemainingCapacity = -1;
 
     public TaskQueue() {
         super();
@@ -109,18 +110,22 @@ public class TaskQueue extends 
LinkedBlockingQueue<Runnable> {
 
     @Override
     public int remainingCapacity() {
-        if (forcedRemainingCapacity != null) {
+        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.intValue();
+            return forcedRemainingCapacity;
         }
         return super.remainingCapacity();
     }
 
-    public void setForcedRemainingCapacity(Integer forcedRemainingCapacity) {
+    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 dbabc05..7298efa 100644
--- a/java/org/apache/tomcat/util/threads/ThreadPoolExecutor.java
+++ b/java/org/apache/tomcat/util/threads/ThreadPoolExecutor.java
@@ -197,7 +197,7 @@ public class ThreadPoolExecutor extends 
java.util.concurrent.ThreadPoolExecutor
             // 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(Integer.valueOf(0));
+            taskQueue.setForcedRemainingCapacity(0);
         }
 
         // setCorePoolSize(0) wakes idle threads
@@ -209,7 +209,7 @@ public class ThreadPoolExecutor extends 
java.util.concurrent.ThreadPoolExecutor
 
         if (taskQueue != null) {
             // ok, restore the state of the queue and pool
-            taskQueue.setForcedRemainingCapacity(null);
+            taskQueue.resetForcedRemainingCapacity();
         }
         this.setCorePoolSize(savedCorePoolSize);
     }


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org
For additional commands, e-mail: dev-h...@tomcat.apache.org

Reply via email to