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

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


The following commit(s) were added to refs/heads/main by this push:
     new 70ebbe75ad Add support for namePrefix to the virtual thread executor
70ebbe75ad is described below

commit 70ebbe75ad397d4dc9278a78e58dc1b805fee6a3
Author: Mark Thomas <ma...@apache.org>
AuthorDate: Fri May 12 10:40:10 2023 +0100

    Add support for namePrefix to the virtual thread executor
---
 java/org/apache/catalina/core/VirtualThreadExecutor.java | 11 ++++++++++-
 webapps/docs/config/executor.xml                         |  9 ++++++++-
 2 files changed, 18 insertions(+), 2 deletions(-)

diff --git a/java/org/apache/catalina/core/VirtualThreadExecutor.java 
b/java/org/apache/catalina/core/VirtualThreadExecutor.java
index b5ed201b16..98fa1edee4 100644
--- a/java/org/apache/catalina/core/VirtualThreadExecutor.java
+++ b/java/org/apache/catalina/core/VirtualThreadExecutor.java
@@ -28,6 +28,7 @@ public class VirtualThreadExecutor extends LifecycleMBeanBase 
implements Executo
 
     private String name;
     private Thread.Builder threadBuilder;
+    private String namePrefix;
 
     public void setName(String name) {
         this.name = name;
@@ -38,6 +39,14 @@ public class VirtualThreadExecutor extends 
LifecycleMBeanBase implements Executo
         return name;
     }
 
+    public String getNamePrefix() {
+        return namePrefix;
+    }
+
+    public void setNamePrefix(String namePrefix) {
+        this.namePrefix = namePrefix;
+    }
+
     @Override
     public void execute(Runnable command) {
         threadBuilder.start(command);
@@ -46,7 +55,7 @@ public class VirtualThreadExecutor extends LifecycleMBeanBase 
implements Executo
 
     @Override
     protected void startInternal() throws LifecycleException {
-        threadBuilder = Thread.ofVirtual().name(getName() + "-", 0);
+        threadBuilder = Thread.ofVirtual().name(getNamePrefix(), 0);
         setState(LifecycleState.STARTING);
     }
 
diff --git a/webapps/docs/config/executor.xml b/webapps/docs/config/executor.xml
index 55ca482d8a..abffc9f5d1 100644
--- a/webapps/docs/config/executor.xml
+++ b/webapps/docs/config/executor.xml
@@ -130,7 +130,14 @@
   <p>The <code>className</code> attribute must be 
<code>org.apache.catalina.core.VirtualThreadExecutor</code> to use
      this implementation.</p>
 
-  <p>The virtual thread implementation does not support any additional 
attributes.</p>
+  <p>The virtual thread implementation supports the follow attributes:</p>
+
+  <attributes>
+    <attribute name="namePrefix" required="false">
+      <p>(String) The name prefix for each thread created by the executor.
+         The thread name for an individual thread will be 
<code>namePrefix+threadNumber</code></p>
+    </attribute>
+  </attributes>
 
   </subsection>
 


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

Reply via email to