You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by ma...@apache.org on 2023/02/24 12:24:42 UTC

[tomcat] branch main updated: Refactor to remove use of ThreadLocal

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

commit 4fe7e810b687d273642208718253e1ec2848967c
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 54c3185cec..7443b2cb6a 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 3278af6ab6..1e38610581 100644
--- a/java/org/apache/coyote/Request.java
+++ b/java/org/apache/coyote/Request.java
@@ -735,7 +735,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-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org