在找netty分配内存时
ByteBufAllocator.DEFAULT.directBuffer(4);
最终进入到PooledByteBufAllocator.newDirectBuffer,首先就找threadCache分配,这就是一个FastThreadLocal
protected ByteBuf newDirectBuffer(int initialCapacity, int maxCapacity) {
PoolThreadCache cache = threadCache.get();
PoolArena directArena = cache.directArena;
。。。
。。。
我们看看FastThreadLocal(简称ftl)和ThreadLocal(简称tl)区别在哪?为什么说ftl要配合ftlt(FastThreadLocalThread)使用性能才高于tl?
首先看ThreadLocal实现:



