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 413bda850c Refactor to remove use of ThreadLocal
413bda850c is described below

commit 413bda850ca8c9c507cf1eecf449ff55dc50a1d9
Author: Mark Thomas <ma...@apache.org>
AuthorDate: Fri Feb 24 12:23:22 2023 +0000

    Refactor to remove use of ThreadLocal
    
    ThreadLocal.get() calls Thread.currentThread() so caching the thread (or
    its attributes) in a ThreadLocal doesn't offer any performance benefits.
---
 java/org/apache/catalina/connector/CoyoteAdapter.java | 6 ------
 java/org/apache/coyote/Request.java                   | 4 +++-
 2 files changed, 3 insertions(+), 7 deletions(-)

diff --git a/java/org/apache/catalina/connector/CoyoteAdapter.java 
b/java/org/apache/catalina/connector/CoyoteAdapter.java
index 1469631138..40edce0b11 100644
--- a/java/org/apache/catalina/connector/CoyoteAdapter.java
+++ b/java/org/apache/catalina/connector/CoyoteAdapter.java
@@ -75,12 +75,8 @@ public class CoyoteAdapter implements Adapter {
     public static final int ADAPTER_NOTES = 1;
 
 
-    private static final ThreadLocal<String> THREAD_NAME = ThreadLocal
-            .withInitial(() -> Thread.currentThread().getName());
-
     // ----------------------------------------------------------- Constructors
 
-
     /**
      * Construct a new CoyoteProcessor associated with the specified connector.
      *
@@ -125,7 +121,6 @@ public class CoyoteAdapter implements Adapter {
         boolean success = true;
         AsyncContextImpl asyncConImpl = request.getAsyncContextInternal();
 
-        req.getRequestProcessor().setWorkerThreadName(THREAD_NAME.get());
         req.setRequestThread();
 
         try {
@@ -333,7 +328,6 @@ public class CoyoteAdapter implements Adapter {
         boolean async = false;
         boolean postParseSuccess = false;
 
-        req.getRequestProcessor().setWorkerThreadName(THREAD_NAME.get());
         req.setRequestThread();
 
         try {
diff --git a/java/org/apache/coyote/Request.java 
b/java/org/apache/coyote/Request.java
index 4cd6bc215d..e06530e217 100644
--- a/java/org/apache/coyote/Request.java
+++ b/java/org/apache/coyote/Request.java
@@ -723,7 +723,9 @@ public final class Request {
     }
 
     public void setRequestThread() {
-        threadId = Thread.currentThread().getId();
+        Thread t = Thread.currentThread();
+        threadId = t.getId();
+        getRequestProcessor().setWorkerThreadName(t.getName());
     }
 
     public boolean isRequestThread() {


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

Reply via email to