Why PoolThreadLocalCache class initialValue method use synchronized ???
See original GitHub issuefinal class PoolThreadLocalCache extends FastThreadLocal<PoolThreadCache> {
private final boolean useCacheForAllThreads;
PoolThreadLocalCache(boolean useCacheForAllThreads) {
this.useCacheForAllThreads = useCacheForAllThreads;
}
@Override
protected synchronized PoolThreadCache initialValue() {
final PoolArena<byte[]> heapArena = leastUsedArena(heapArenas);
final PoolArena<ByteBuffer> directArena = leastUsedArena(directArenas);
final Thread current = Thread.currentThread();
if (useCacheForAllThreads || current instanceof FastThreadLocalThread) {
final PoolThreadCache cache = new PoolThreadCache(
heapArena, directArena, tinyCacheSize, smallCacheSize, normalCacheSize,
DEFAULT_MAX_CACHED_BUFFER_CAPACITY, DEFAULT_CACHE_TRIM_INTERVAL);
if (DEFAULT_CACHE_TRIM_INTERVAL_MILLIS > 0) {
final EventExecutor executor = ThreadExecutorMap.currentExecutor();
if (executor != null) {
executor.scheduleAtFixedRate(trimTask, DEFAULT_CACHE_TRIM_INTERVAL_MILLIS,
DEFAULT_CACHE_TRIM_INTERVAL_MILLIS, TimeUnit.MILLISECONDS);
}
}
return cache;
}
// No caching so just use 0 as sizes.
return new PoolThreadCache(heapArena, directArena, 0, 0, 0, 0, 0);
}
I think that’s unnecessary, initialValue method use synchronized ???
Issue Analytics
- State:
- Created 4 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
java - Do operations on ThreadLocal have to be synchronized?
ThreadLocal is itself a threadsafety mechanism, and it manages its threadsafety better than you could get by tacking on synchronized anyway.
Read more >io.netty.buffer.PooledByteBufAllocator$PoolThreadLocalCache java ...
@Override protected synchronized PoolThreadCache initialValue() { final PoolArena<byte[]> heapArena = leastUsedArena(heapArenas); final ...
Read more >Allocate from Thread's Cache - Happy Coding
The initalValue method for PoolThreadLocalCache. @Override protected synchronized PoolThreadCache initialValue() { final PoolArena<byte[]> ...
Read more >Synchronization - Learning Java, 4th Edition [Book] - O'Reilly
Fortunately, Java makes the process of synchronizing access to resources ... All static synchronized methods in a class use the same class object...
Read more >PooledByteBufAllocator
getInstance(PooledByteBufAllocator.class); private static final int ... spots as * allocation and de-allocation needs to be synchronized on the PoolArena.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@normanmaurer,https://github.com/netty/netty/issues/9284 About FastThreadLocal Cache line padding I haven’t figured it out yet, hope you can explain. Thank you
@jiangxinlingdu thanks a lot! https://github.com/netty/netty/pull/9357