Wrapper that implements an optimized ThreadLocal access pattern ideal for heavily used ThreadLocals. It is faster to use a mutable holder object and always perform ThreadLocal.get() and never use ThreadLocal.set(), because the value is more likely to be found in the ThreadLocalMap direct hash slot and avoid the slow path of ThreadLocalMap.getEntryAfterMiss(). WARNING: Closing of the returned Scope MUST be called in the same thread as store(..) was originally called.
Credit to @trask from the FastThreadLocal in glowroot. One small change is that we don't use an kamon-defined holder object as that would prevent class unloading.
- Companion:
- object