persistence@glassfish.java.net

Re: Some questions about HardWeak/SoftWeak cache

From: Gordon Yorke <gordon.yorke_at_oracle.com>
Date: Thu, 22 May 2008 00:05:55 -0400

This is interesting... What you are seeing in the second call
(getSize(Class, boolean)) is that the 'dead' cachekeys are not being
reported because they have no object and the class comparison fails.
With the first call (getSize()) there is no class check so all of the
cachekeys are being counted even the 'dead' (garbage collected
references).
This code is considered internal and it seems that I sent you down the
incorrect path by mentioning the first method. The second method is the
only way to verify the actually number of objects in the cache. The
first method (getSize()) returns the number of references currently in
the cache (both active and gc'd). Both values will fluctuate in an
active cache as the gc'd references are released from the cache but they
give very different results.
--Gordon

jasonw41 wrote:
> Hi Gordon,
>
> Thanks for your reply. My test is:
> 1. Entity cache type: HardWeak; size: 35
> 2. Use a session bean to manage persist, gc and getSize by three bean
> methods
> 3. Persist 50 entities
> 4. Call gc() a couple of time to clean the weak references
> 5. Call xxx.getSize() and then call xxx.getSize(MyEntity.class,true);
>
> The first one gives result 50 and the second one gives 35. I tried several
> times and always get the same results. I was wondering if the first one
> should return 35 as well.
>
>
>