(sun) GC scans live objects. it is assumed that there are paths of more dead objects than living objects in a typical executable program of a Java program. he marks living objects and leaves the rest.
if you cache a lot of objects, they all live. and if you have several GB of such objects, the GC is going to spend a lot of time scanning them in vain. long pauses of GC can paralyze your application.
caching something just to make it not garbage does not help GC.
not to say that caching is wrong. if you have 15G memory and your database 10G, why not cache everything in memory, so the answers are quickly covered. note that this is caching something that would otherwise be slow to fetch.
in order to prevent fruitless scans of the 10G cache, the cache must be out of GC control. For example, use "memcached", which lives in a different process, and has its own cache optimized GC.
the latest news is Terracotta BigMemory, which is a pure Java solution that does similar.
An example of a local thread pool is the direct ByteBuffer pool. when we call
channel.read(byteBuffer)
if byteBuffer is not βdirect,β βdirectβ should be highlighted under the hood, which is used to exchange data with the OS. in a network application, such distributions can be very frequent, it seems that this is a waste in order to discard the just allocated and immediately select the other in the next statement. Sun engineers, apparently, do not really trust GC, created a stream of local pool of "direct" ByteBuffers.
source share