Hello

sob., 4 sty 2020 o 02:58 Monica Ron <[email protected]> napisał(a):

> The new code works for me. Once we deploy our wars, we don't generally
> re-deploy until we have a new release, and we usually shutdown the
> Glassfish/Payara domain to do that deployment. So, shutting down the JVM
> obviously clears all memory.
>
> I'm not really worried (I think our code should be fine, based on how we
> use it), but I do have one question:
> Hasn't the garbage-collection behavior changed by changing the original 
> WeakHashMap<Logger,
> String> (if generics had been added to the code as it is in 1.10.x [with
> separate m_loggers for each logging API] without otherwise changing
> underlying code) to WeakHashMap<String, List<Logger>>?
>

Actually both cases are a bit incorrect IMO... My new case (weak map of
string → list<Logger>) only ensures that we don't loose loggers, but
doesn't do any weak-functionality (because the logger strongly references
key anyway). Previous case (weak map of logger → string) was better, but
keys (loggers) were mostly used by strong references anyway throughout the
code - because most libraries use "logger log = loggerFactory.getLogger()"
idiom all the time - and mostly using static references, so the weak keys
of old WeakHashMap<Logger, String> were not released anyway.

In pax-logging 1.11.x+, the List<Logger> is definitely not weak, but
activator of pax-logging-api explicitly clears this list when everything is
done, so it's even better (IMO).


>
> For 1.11.x, the change made for PAXLOGGING-307 was:
> public static final Map<String, PaxLoggingManagerAwareLogger> m_loggers =
> new WeakHashMap<String, PaxLoggingManagerAwareLogger>();
> became:
> public static final List<PaxLoggingManagerAwareLogger> m_loggers = new
> LinkedList<>();
>
> Based on the pre-generics code, the 1.11.x map should have had the logger
> as the key:
> public static final Map<PaxLoggingManagerAwareLogger, String> m_loggers =
> new WeakHashMap<PaxLoggingManagerAwareLogger, String>();
>
>
> For a WeakHashMap, if all of the other references to the key got discarded
> elsewhere, the key-value pair automatically gets discarded from the
> WeakHashMap, correct? So, if an instance of a class with a reference to a
> PaxLoggingManagerAwareLogger (or Logger [of whatever logging API you used]
> for 1.10.x) got garbage-collected, the logger would also have been removed
> from m_loggers, correct? This automatic removal from m_loggers will not
> occur with a List<PaxLoggingManagerAwareLogger> (for 1.11.x), or with a 
> WeakHashMap<String,
> List<Logger>> (for 1.10.x).
>

For 1.11.x it's removed explicitly here:
https://github.com/ops4j/org.ops4j.pax.logging/blob/logging-1.11.4/pax-logging-api/src/main/java/org/ops4j/pax/logging/internal/Activator.java#L143-L155

For 1.10.x, taking into account the fact that loggers are created once and
mostly held statictly, it's not a big issue IMO.


>
> As I said, I don't think this will be a problem for us, but it may be
> something to consider, if the original WeakHashMap was by intention to help
> with garbage collection. By this time, no one may know what the original
> intention is...
>

:)

regards
Grzegorz Grzybek


> Thanks again,
> Monica
>
>
> --
> --
> ------------------
> OPS4J - http://www.ops4j.org - [email protected]
>
> ---
> You received this message because you are subscribed to the Google Groups
> "OPS4J" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ops4j/d4a9fb64-9389-4d08-9b3e-8a735b57d6ef%40googlegroups.com
> <https://groups.google.com/d/msgid/ops4j/d4a9fb64-9389-4d08-9b3e-8a735b57d6ef%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>

-- 
-- 
------------------
OPS4J - http://www.ops4j.org - [email protected]

--- 
You received this message because you are subscribed to the Google Groups 
"OPS4J" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ops4j/CAAdXmhpToYfJ%2Bqgsp1%3DQ1HWQg5kSAqr31%3DSbizwG6xi8yG7u1A%40mail.gmail.com.

Reply via email to