RFR 9: 8138696 : java.lang.ref.Cleaner - an easy to use alternative to finalization

Roger Riggs Roger.Riggs at Oracle.com
Thu Oct 1 14:59:04 UTC 2015

Hi Moh,

On 10/1/2015 10:28 AM, Rezaei, Mohammad A. wrote:
> The proposed API makes good sense for what I would consider coarse grained cleanup.
> There is another significant use case for Weak/Soft references that is not covered here: weak/soft references used in cache like data structures, e.g. WeakHashMap.
Correct, the existing implementation handles its WeakReferences without 
the need for a
second thread to be involved and avoids any resulting concurrency issues.
There is no need to reimplement classes that already handle weak and 
soft references,
most have already been tuned for optimal behavior and performance.
> Wouldn't there be significant code reuse if I could register a ReferenceQueue and get callbacks when appropriate?
> (Just like other uses of this cleaner, any user of this api has to pay attention to concurrency, so WeakHashMap, as is, is not a great candidate for this).
Right, any registration type of mechanism would need to be concerned 
with concurrency
and with the robustness of the thread being shared to do the callbacks.
Some thread would need to wait on multiple ReferenceQueues which would 
require a low level wait
for multiple locks.


> Thanks
> Moh
>> -

More information about the core-libs-dev mailing list