by layer8 · 3y ago · 0 comments
What is the problem here? Just the per-virtual-thread memory consumption by the variable when it is used (which would be expected)?
However, if suddenly you have a million threads then this optimization doesn't work anymore. Sure, the concept of ThreadLocal still works, but in practice you'll end up creating a million of these heavy objects - something you wanted to avoid!
Using a ThreadLocal is (usually) a code smell. It's optimized / supposed to be used with just a few threads, not millions.