This is an automated email from the ASF dual-hosted git repository.
markt pushed a commit to branch 10.1.x
in repository https://gitbox.apache.org/repos/asf/tomcat.git
The following commit(s) were added to refs/heads/10.1.x by this push:
new 3bd3d0f9b8 Refactor TaskQueue to use RetryableQueue interface
3bd3d0f9b8 is described below
commit 3bd3d0f9b80dc629deaec98c3283e13e21a03c04
Author: PauloMigAlmeida <[email protected]>
AuthorDate: Mon May 26 21:35:06 2025 +1200
Refactor TaskQueue to use RetryableQueue interface
Additional clean-up by markt
---
.../apache/tomcat/util/threads/RetryableQueue.java | 33 ++++++++++++++++++++++
java/org/apache/tomcat/util/threads/TaskQueue.java | 11 ++------
.../tomcat/util/threads/ThreadPoolExecutor.java | 4 +--
webapps/docs/changelog.xml | 11 ++++++++
4 files changed, 48 insertions(+), 11 deletions(-)
diff --git a/java/org/apache/tomcat/util/threads/RetryableQueue.java
b/java/org/apache/tomcat/util/threads/RetryableQueue.java
new file mode 100644
index 0000000000..fe60fe4d9b
--- /dev/null
+++ b/java/org/apache/tomcat/util/threads/RetryableQueue.java
@@ -0,0 +1,33 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.tomcat.util.threads;
+
+import java.util.concurrent.BlockingQueue;
+
+public interface RetryableQueue<T> extends BlockingQueue<T> {
+
+ /**
+ * Used to add a task to the queue if the task has been rejected by the
Executor.
+ *
+ * @param o The task to add to the queue
+ *
+ * @return {@code true} if the task was added to the queue,
+ * otherwise {@code false}
+ */
+ boolean force(T o);
+}
diff --git a/java/org/apache/tomcat/util/threads/TaskQueue.java
b/java/org/apache/tomcat/util/threads/TaskQueue.java
index 7ff4e3e586..bec0fb31c2 100644
--- a/java/org/apache/tomcat/util/threads/TaskQueue.java
+++ b/java/org/apache/tomcat/util/threads/TaskQueue.java
@@ -30,7 +30,7 @@ import org.apache.tomcat.util.res.StringManager;
* there are idle threads and you won't be able to force items onto the queue
* itself.
*/
-public class TaskQueue extends LinkedBlockingQueue<Runnable> {
+public class TaskQueue extends LinkedBlockingQueue<Runnable> implements
RetryableQueue<Runnable> {
private static final long serialVersionUID = 1L;
protected static final StringManager sm =
StringManager.getManager(TaskQueue.class);
@@ -54,14 +54,7 @@ public class TaskQueue extends LinkedBlockingQueue<Runnable>
{
}
- /**
- * Used to add a task to the queue if the task has been rejected by the
Executor.
- *
- * @param o The task to add to the queue
- *
- * @return {@code true} if the task was added to the queue,
- * otherwise {@code false}
- */
+ @Override
public boolean force(Runnable o) {
if (parent == null || parent.isShutdown()) {
throw new
RejectedExecutionException(sm.getString("taskQueue.notRunning"));
diff --git a/java/org/apache/tomcat/util/threads/ThreadPoolExecutor.java
b/java/org/apache/tomcat/util/threads/ThreadPoolExecutor.java
index aef2c6ca89..17651ed1fa 100644
--- a/java/org/apache/tomcat/util/threads/ThreadPoolExecutor.java
+++ b/java/org/apache/tomcat/util/threads/ThreadPoolExecutor.java
@@ -1375,12 +1375,12 @@ public class ThreadPoolExecutor extends
AbstractExecutorService {
try {
executeInternal(command);
} catch (RejectedExecutionException rx) {
- if (getQueue() instanceof TaskQueue) {
+ if (getQueue() instanceof RetryableQueue) {
// If the Executor is close to maximum pool size, concurrent
// calls to execute() may result (due to Tomcat's use of
// TaskQueue) in some tasks being rejected rather than queued.
// If this happens, add them to the queue.
- final TaskQueue queue = (TaskQueue) getQueue();
+ final RetryableQueue<Runnable> queue =
(RetryableQueue<Runnable>) getQueue();
if (!queue.force(command)) {
submittedCount.decrementAndGet();
throw new
RejectedExecutionException(sm.getString("threadPoolExecutor.queueFull"));
diff --git a/webapps/docs/changelog.xml b/webapps/docs/changelog.xml
index 748b14a55e..a9687eaf26 100644
--- a/webapps/docs/changelog.xml
+++ b/webapps/docs/changelog.xml
@@ -118,6 +118,17 @@
</fix>
</changelog>
</subsection>
+ <subsection name="Coyote">
+ <changelog>
+ <scode>
+ <pr>861</pr>: Refactor <code>TaskQueue</code> to use the new interface
+ <code>RetryableQueue</code> which enables better integration of custom
+ <code>Executor</code>s which provide their own
+ <code>BlockingQueue</code> implementation. Pull request provided by
+ Paulo Almeida. (markt)
+ </scode>
+ </changelog>
+ </subsection>
<subsection name="Jasper">
<changelog>
<fix>
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]