This is an automated email from the ASF dual-hosted git repository.
mgrigorov pushed a commit to branch 7.0.x
in repository https://gitbox.apache.org/repos/asf/tomcat.git
The following commit(s) were added to refs/heads/7.0.x by this push:
new cf5226f Change forcedRemainingCapacity from Integer to int
cf5226f is described below
commit cf5226f9eb9d94068f771a015cdbb1bd701b7fb3
Author: Martin Tzvetanov Grigorov <[email protected]>
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 | 14 +++++++++-----
.../org/apache/tomcat/util/threads/ThreadPoolExecutor.java | 4 ++--
2 files changed, 11 insertions(+), 7 deletions(-)
diff --git a/java/org/apache/tomcat/util/threads/TaskQueue.java
b/java/org/apache/tomcat/util/threads/TaskQueue.java
index 600fe5b..cdd0bc2 100644
--- a/java/org/apache/tomcat/util/threads/TaskQueue.java
+++ b/java/org/apache/tomcat/util/threads/TaskQueue.java
@@ -35,8 +35,8 @@ 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 Integer forcedRemainingCapacity = null;
+ // (when stopping a context and firing the listeners)
+ private int forcedRemainingCapacity = -1;
public TaskQueue() {
super();
@@ -105,18 +105,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 6d433d5..24bc84c 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: [email protected]
For additional commands, e-mail: [email protected]