From d578811eaf16a85a428506703fdc8ccab4a49585 Mon Sep 17 00:00:00 2001 From: corby kim Date: Fri, 3 May 2024 11:58:59 +0900 Subject: [PATCH 1/2] [UNDERTOW-2385] Modify ThreadLocalCache using WeakHashMap --- .../java/io/undertow/server/DefaultByteBufferPool.java | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/core/src/main/java/io/undertow/server/DefaultByteBufferPool.java b/core/src/main/java/io/undertow/server/DefaultByteBufferPool.java index c28aef4818..7ef575c3a7 100644 --- a/core/src/main/java/io/undertow/server/DefaultByteBufferPool.java +++ b/core/src/main/java/io/undertow/server/DefaultByteBufferPool.java @@ -24,11 +24,7 @@ import java.lang.ref.WeakReference; import java.nio.ByteBuffer; -import java.util.ArrayDeque; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; +import java.util.*; import java.util.concurrent.ConcurrentLinkedQueue; import java.util.concurrent.atomic.AtomicIntegerFieldUpdater; @@ -343,7 +339,7 @@ protected void finalize() throws Throwable { // class can be called by a different thread than the one that initialized the data. private static class ThreadLocalCache { - Map localsByThread = new HashMap<>(); + Map localsByThread = new WeakHashMap<>(); ThreadLocalData get() { return localsByThread.get(Thread.currentThread()); From f1f959e6f512ced96515bfad4da54fe7054b8bdc Mon Sep 17 00:00:00 2001 From: corby kim Date: Tue, 7 May 2024 09:57:46 +0900 Subject: [PATCH 2/2] [UNDERTOW-2385] Avoid star import --- .../main/java/io/undertow/server/DefaultByteBufferPool.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/core/src/main/java/io/undertow/server/DefaultByteBufferPool.java b/core/src/main/java/io/undertow/server/DefaultByteBufferPool.java index 7ef575c3a7..932680d10a 100644 --- a/core/src/main/java/io/undertow/server/DefaultByteBufferPool.java +++ b/core/src/main/java/io/undertow/server/DefaultByteBufferPool.java @@ -24,7 +24,11 @@ import java.lang.ref.WeakReference; import java.nio.ByteBuffer; -import java.util.*; +import java.util.ArrayDeque; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.WeakHashMap; import java.util.concurrent.ConcurrentLinkedQueue; import java.util.concurrent.atomic.AtomicIntegerFieldUpdater;