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

markt pushed a commit to branch 11.0.x
in repository https://gitbox.apache.org/repos/asf/tomcat.git


The following commit(s) were added to refs/heads/11.0.x by this push:
     new 5d2d7f98ad Refactor TaskQueue to use RetryableQueue interface
5d2d7f98ad is described below

commit 5d2d7f98ad614b4892868264ed270634938b5761
Author: PauloMigAlmeida <paulo.miguel.almeida.rode...@gmail.com>
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    |  2 +-
 webapps/docs/changelog.xml                         | 11 ++++++++
 4 files changed, 47 insertions(+), 10 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 fda8d1c244..1b5f730c6a 100644
--- a/java/org/apache/tomcat/util/threads/TaskQueue.java
+++ b/java/org/apache/tomcat/util/threads/TaskQueue.java
@@ -31,7 +31,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> {
 
     @Serial
     private static final long serialVersionUID = 1L;
@@ -56,14 +56,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 2e5be26325..c32769a1e0 100644
--- a/java/org/apache/tomcat/util/threads/ThreadPoolExecutor.java
+++ b/java/org/apache/tomcat/util/threads/ThreadPoolExecutor.java
@@ -1335,7 +1335,7 @@ public class ThreadPoolExecutor extends 
AbstractExecutorService {
         try {
             executeInternal(command);
         } catch (RejectedExecutionException rx) {
-            if (getQueue() instanceof TaskQueue queue) {
+            if (getQueue() instanceof RetryableQueue<Runnable> queue) {
                 // 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.
diff --git a/webapps/docs/changelog.xml b/webapps/docs/changelog.xml
index bf6ca589d3..a7f818aca7 100644
--- a/webapps/docs/changelog.xml
+++ b/webapps/docs/changelog.xml
@@ -127,6 +127,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: dev-unsubscr...@tomcat.apache.org
For additional commands, e-mail: dev-h...@tomcat.apache.org

Reply via email to