-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
Replace ThreadLocal cache with ThreadIdCache #11504
Replace ThreadLocal cache with ThreadIdCache #11504
Conversation
Use a cache class that will work better with virtual threads
Use a cache class that will work better with virtual threads
@lorban @sbordet I have now also replaced usages of For non-cache usages of Object oldValue = threadLocal.get();
try
{
threadLocal.set(newValue);
// ...
}
finally
{
threadLocal.set(oldValue);
} to be replaced with the pattern (probably with help of a utility method): Object oldValue = threadLocal.get();
try
{
threadLocal.set(newValue);
// ...
}
finally
{
if (oldValue == null)
threadLocal.remove();
else
threadLocal.set(oldValue);
} or maybe even (@lorban is this worth the extra if?) Object oldValue = threadLocal.get();
try
{
threadLocal.set(newValue);
// ...
}
finally
{
if (oldValue == null && VirtualThreads.isVirtualThread())
threadLocal.remove();
else
threadLocal.set(oldValue);
} thoughts? |
{ | ||
if (capacity >= 0) | ||
return capacity; | ||
return 2 * ProcessorUtils.availableProcessors(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Prooooobably just the number of cores is right!
jetty-core/jetty-util/src/main/java/org/eclipse/jetty/util/thread/ThreadIdCache.java
Outdated
Show resolved
Hide resolved
jetty-core/jetty-util/src/main/java/org/eclipse/jetty/util/thread/ThreadIdCache.java
Outdated
Show resolved
Hide resolved
jetty-core/jetty-util/src/main/java/org/eclipse/jetty/util/thread/ThreadIdCache.java
Outdated
Show resolved
Hide resolved
jetty-core/jetty-util/src/main/java/org/eclipse/jetty/util/thread/ReservedThreadExecutor.java
Outdated
Show resolved
Hide resolved
jetty-core/jetty-util/src/main/java/org/eclipse/jetty/util/thread/ThreadIdCache.java
Outdated
Show resolved
Hide resolved
jetty-core/jetty-util/src/main/java/org/eclipse/jetty/util/thread/ThreadIdCache.java
Outdated
Show resolved
Hide resolved
jetty-core/jetty-util/src/main/java/org/eclipse/jetty/util/thread/ThreadIdCache.java
Outdated
Show resolved
Hide resolved
jetty-core/jetty-util/src/main/java/org/eclipse/jetty/util/thread/ThreadIdCache.java
Outdated
Show resolved
Hide resolved
jetty-core/jetty-util/src/main/java/org/eclipse/jetty/util/thread/ThreadIdCache.java
Outdated
Show resolved
Hide resolved
and updates from review
2a543ac
into
experiment/jetty-12.0.x/reservedThreadExecutor
I have merged this to #11498, where is can be further reviewed. |
Use a cache class that will work better with virtual threads.
This generalized the "Pool-lite" algorithm introduced in PR #11498 to provide a cache that can be used to fix #10568