Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid using ThreadLocals for caching expensive resources #2206

Open
OndroMih opened this issue Mar 25, 2024 · 1 comment
Open

Avoid using ThreadLocals for caching expensive resources #2206

OndroMih opened this issue Mar 25, 2024 · 1 comment

Comments

@OndroMih
Copy link

In order to avoid performance degradation when using virtual threads (see #2185), usage of thread locals for caching resources should be minimized or completely avoided.

Acording to the comment #2185 (comment), 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>() {
@laurentschoelens
Copy link

@OndroMih : working on this issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants