just want to clarify my understanding of that code
Reference<Keyword> existingRef = table.get(sym);
if(existingRef == null) // keyword was not found
{
Util.clearCache(rq, table); // force cleaning of the dead weak references in the whole cache
....create new keyword and store it wrapped into WeakReference in the cache
}
Maybe i am missing something but what are the reasons/assumptions to force cache clearing from dead weak references on every cache miss if rq is not empty, i.e. there is seq scan of the whole cache to locate dead references and to remove them.
And seq scan is executed during Keyword function calling, i.e. blocks the caller.
Naive alternative is to dedicate a thread which collects the garbage from the cache with a some period (~10 seconds or smth like that)