[
https://issues.apache.org/jira/browse/LOG4J2-3622?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17622871#comment-17622871
]
Volkan Yazici commented on LOG4J2-3622:
---------------------------------------
Thread-locals are used in various places in Log4j for performance purposes.
{{ReusableMessageFactory}} is just the tip of the iceberg.
AFAIU, starting with Java 19, [Loom allows TLs to be bound to
vthreads|https://blogs.oracle.com/javamagazine/post/java-loom-virtual-threads-platform-threads]:
> ... Virtual threads support thread-local behavior the same way as platform
> threads, but because virtual threads can be very numerous, thread locals
> should be used only after careful consideration.
> In fact, as part of Project Loom, many uses of thread locals in the java.base
> module were removed to reduce the memory footprint when code is running with
> millions of threads. There is an interesting alternative for some use cases
> that is currently being explored in a draft JEP for scope-local variables.
I am curious if a vthread can access the TLs of the carrier thread. If
possible, this might a quick-and-dirty fix.
Ideally, we should move {{Recycler}} of {{JsonTemplateLayout}} to the {{-core}}
for object pooling purposes, replace TL usage with {{Recycler}}s, and provide
efficient {{Recycler}} implementations out of box.
> Support for virtual threads
> ---------------------------
>
> Key: LOG4J2-3622
> URL: https://issues.apache.org/jira/browse/LOG4J2-3622
> Project: Log4j 2
> Issue Type: Bug
> Components: Core
> Reporter: liuxichen
> Priority: Critical
>
> I noticed in ReusableMessageFactory threadlocal are used, so If a am using
> jdk19 virtual threads while logging with threadlocal disabled,
> UnsupportedOperationException would be thrown, and using log in a lot of
> virtual threads might create a lot of useless objects, could you please fix
> this?
--
This message was sent by Atlassian Jira
(v8.20.10#820010)