"threadlocal hashmap vs concurrenthashmap for thread-safe unbound caches" Code Answer

1

use threadlocal as cache is a not good practice

in most containers, threads are reused via thread pools and thus are never gc. this would lead something wired

use concurrenthashmap you have to manage it in order to prevent mem leak

if you insist, i suggest using week or soft ref and evict after rich maxsize

if you are finding a in mem cache solution ( do not reinventing the wheel ) try guava cache http://docs.guava-libraries.googlecode.com/git/javadoc/com/google/common/cache/cachebuilder.html

By Oscerd on January 12 2022
Only authorized users can answer the Search term. Please sign in first, or register a free account.