This is an automated email from the ASF dual-hosted git repository.
markt pushed a commit to branch 9.0.x
in repository https://gitbox.apache.org/repos/asf/tomcat.git
The following commit(s) were added to refs/heads/9.0.x by this push:
new 69a33aae6a Refactor to remove use of ThreadLocal
69a33aae6a is described below
commit 69a33aae6a4971c21d566b92827858e2b0df692a
Author: Mark Thomas <[email protected]>
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 | 7 -------
java/org/apache/coyote/Request.java | 4 +++-
2 files changed, 3 insertions(+), 8 deletions(-)
diff --git a/java/org/apache/catalina/connector/CoyoteAdapter.java
b/java/org/apache/catalina/connector/CoyoteAdapter.java
index 9733bf9f5a..4fc929c85b 100644
--- a/java/org/apache/catalina/connector/CoyoteAdapter.java
+++ b/java/org/apache/catalina/connector/CoyoteAdapter.java
@@ -73,17 +73,12 @@ public class CoyoteAdapter implements Adapter {
public static final int ADAPTER_NOTES = 1;
-
protected static final boolean ALLOW_BACKSLASH = Boolean
.parseBoolean(System.getProperty("org.apache.catalina.connector.CoyoteAdapter.ALLOW_BACKSLASH",
"false"));
- private static final ThreadLocal<String> THREAD_NAME = ThreadLocal
- .withInitial(() -> Thread.currentThread().getName());
-
// ----------------------------------------------------------- Constructors
-
/**
* Construct a new CoyoteProcessor associated with the specified connector.
*
@@ -128,7 +123,6 @@ public class CoyoteAdapter implements Adapter {
boolean success = true;
AsyncContextImpl asyncConImpl = request.getAsyncContextInternal();
- req.getRequestProcessor().setWorkerThreadName(THREAD_NAME.get());
req.setRequestThread();
try {
@@ -336,7 +330,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 a0f5d68b81..56d7b74b0a 100644
--- a/java/org/apache/coyote/Request.java
+++ b/java/org/apache/coyote/Request.java
@@ -675,7 +675,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: [email protected]
For additional commands, e-mail: [email protected]