On Tue, 29 Jun 2021 19:35:40 GMT, Weijun Wang <wei...@openjdk.org> wrote:

>> Using a HashSet<Class> could use the callerClass as the key and be a stable 
>> reference for having given the message.
>> or use a ConcurrentHashMap<Class<?>>, boolean> and avoid any separate 
>> synchronization that would be needed with a HashSet or HashMap.
>
> If I switch to a "non-weak" set or map, then it seems I can safely use the 
> source string as the key. Will using the Class object as a key prevent them 
> from unloading?

Using a synchronized WeakHashMap with the class as the key would not prevent 
class unloading.
Using a non-weak set or map to strings would keep the strings around for the 
life of the runtime.

-------------

PR: https://git.openjdk.java.net/jdk17/pull/166

Reply via email to