In order to avoid performance degradation when using virtual threads (see https://github.com/eclipse-ee4j/grizzly/pull/2185), usage of thread locals for caching resources should be minimized or completely avoided.
modules/grizzly/src/main/java/org/glassfish/grizzly/ThreadCache.java:36: private static final ThreadLocal<ObjectCache> genericCacheAttr = new ThreadLocal<>();
Some variables potentially used for caching - if not used for caching, may remain as is:
modules/comet/src/main/java/org/glassfish/grizzly/comet/CometContext.java:101: protected final static ThreadLocal<Request> REQUEST_LOCAL = new ThreadLocal<>();
modules/http-servlet/src/main/java/org/glassfish/grizzly/servlet/WebappContext.java:144: private final ThreadLocal<DispatchData> dispatchData = new ThreadLocal<>();
Thread-unsafe formatters cached for performance purposes - these should be replaced by global DateTimeFormatter instances, which is thread-safe and can be reused by multiple threads:
modules/http/src/main/java/org/glassfish/grizzly/http/util/CookieUtils.java:73: public static final ThreadLocal<SimpleDateFormat> OLD_COOKIE_FORMAT = new ThreadLocal<SimpleDateFormat>() {
modules/http/src/main/java/org/glassfish/grizzly/http/util/FastHttpDateFormat.java:55: private static final ThreadLocal<SimpleDateFormatter> FORMAT = new ThreadLocal<SimpleDateFormatter>() {
In order to avoid performance degradation when using virtual threads (see https://github.com/eclipse-ee4j/grizzly/pull/2185), usage of thread locals for caching resources should be minimized or completely avoided.
Acording to the comment https://github.com/eclipse-ee4j/grizzly/pull/2185#issuecomment-1787016453, there are a few ThreadLocal variables used as cache:
Thread cache:
modules/grizzly/src/main/java/org/glassfish/grizzly/ThreadCache.java:36: private static final ThreadLocal<ObjectCache> genericCacheAttr = new ThreadLocal<>();
Some variables potentially used for caching - if not used for caching, may remain as is:
modules/comet/src/main/java/org/glassfish/grizzly/comet/CometContext.java:101: protected final static ThreadLocal<Request> REQUEST_LOCAL = new ThreadLocal<>();
modules/http-servlet/src/main/java/org/glassfish/grizzly/servlet/WebappContext.java:144: private final ThreadLocal<DispatchData> dispatchData = new ThreadLocal<>();
Thread-unsafe formatters cached for performance purposes - these should be replaced by global
DateTimeFormatter
instances, which is thread-safe and can be reused by multiple threads:modules/http/src/main/java/org/glassfish/grizzly/http/util/CookieUtils.java:73: public static final ThreadLocal<SimpleDateFormat> OLD_COOKIE_FORMAT = new ThreadLocal<SimpleDateFormat>() {
modules/http/src/main/java/org/glassfish/grizzly/http/util/FastHttpDateFormat.java:55: private static final ThreadLocal<SimpleDateFormatter> FORMAT = new ThreadLocal<SimpleDateFormatter>() {