m_loggers = new WeakHashMap();
m_loggers = new WeakHashMap<String, JclLogger>(); // Or <String, Slf4jLogger>, or <String, Logger>, etc., depending on type.
m_loggers = new WeakHashMap<JclLogger, String>(); // Or <Slf4jLogger, String>, or <Logger, String>, etc., depending on type.
public Log getInstance(String name)
throws LogConfigurationException
{
PaxLogger logger;
if (m_paxLogging == null)
{
logger = FallbackLogFactory.createFallbackLog(null, name);
}
else
{
logger = m_paxLogging.getLogger(name, JclLogger.JCL_FQCN);
}
JclLogger jclLogger = new JclLogger(logger);
synchronized (m_loggers) {
m_loggers.put(jclLogger, name); // THIS LINE GOT CHANGED WHEN YOU ADDED GENERICS. KEY/VALUE GOT SWAPPED.
}
return jclLogger;
}
m_loggers.put(name, jclLogger); // THIS LINE GOT CHANGED WHEN YOU ADDED GENERICS.
--
--
------------------
OPS4J - http://www.ops4j.org - op...@googlegroups.com
---
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 ops4j+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ops4j/952b7207-cd2b-4229-af4a-f60c934d2c1f%40googlegroups.com.
I'll run into the same issue I saw with the actual 1.10.4. When a second logger is registered in that global map with a name that already exists, the first logger will be lost
--
--
------------------
OPS4J - http://www.ops4j.org - op...@googlegroups.com
---
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 ops4j+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ops4j/9108d4a5-43cf-45da-ac17-feefe3b56ccc%40googlegroups.com.
--
--
------------------
OPS4J - http://www.ops4j.org - op...@googlegroups.com
---
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 ops4j+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ops4j/80cf1c6a-db69-4463-b85a-5b2b112a27f6%40googlegroups.com.
To unsubscribe from this group and stop receiving emails from it, send an email to op...@googlegroups.com.
To unsubscribe from this group and stop receiving emails from it, send an email to ops4j+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ops4j/132b64d3-6418-47b0-85f7-fd7b9199b8d9%40googlegroups.com.
Hello
To view this discussion on the web visit https://groups.google.com/d/msgid/ops4j/132b64d3-6418-47b0-85f7-fd7b9199b8d9%40googlegroups.com.
To unsubscribe from this group and stop receiving emails from it, send an email to ops4j+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ops4j/96f01aae-bbb3-4b76-bcc8-9b9f050d1e4a%40googlegroups.com.
Thank you very much. I spent many hours trying to figure out what was wrong with my updated POM files and Payara5 deployment before I finally realized that the problem was with Pax Logging, not with my own code. I am glad you were able to fix this and make a new official release of 1.10.x before we released our code for running on Payara5.
--
--
------------------
OPS4J - http://www.ops4j.org - op...@googlegroups.com
---
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 ops4j+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ops4j/9fb4447d-3a87-4215-83ac-f5cd0078744a%40googlegroups.com.
To unsubscribe from this group and stop receiving emails from it, send an email to op...@googlegroups.com.
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>>?
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).
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...
Thanks again,Monica
--
--
------------------
OPS4J - http://www.ops4j.org - op...@googlegroups.com
---
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 ops4j+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ops4j/d4a9fb64-9389-4d08-9b3e-8a735b57d6ef%40googlegroups.com.
Hello
To unsubscribe from this group and stop receiving emails from it, send an email to op...@googlegroups.com.
To unsubscribe from this group and stop receiving emails from it, send an email to ops4j+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ops4j/fdd62aeb-e3ae-4d33-879f-6c54d4ddce43%40googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ops4j/fdd62aeb-e3ae-4d33-879f-6c54d4ddce43%40googlegroups.com.
To unsubscribe from this group and stop receiving emails from it, send an email to ops4j+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ops4j/abc30993-9caf-461a-a675-50cfa95ddf03%40googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ops4j/abc30993-9caf-461a-a675-50cfa95ddf03%40googlegroups.com.
To unsubscribe from this group and stop receiving emails from it, send an email to ops4j+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ops4j/27968583-d090-43a0-b963-12a923c31fd4%40googlegroups.com.
Once a Logger is created it will not be deleted until the LoggerContext it is associated with is deleted. Typically, this will only happen when the application is shut down or un-deployed. Each call to getLogger with the same logger name will return the same Logger instance.
Thus care should be taken to ensure that value objects do not strongly refer to their own keys
Hello againAfter little more investigation and careful usage of WeakHashMaps and WeakReferences I managed to create 1M of unique loggers on -Xmx128M that were correctly garbage collected in:
- pax-logging-log4j1
- pax-logging-log4j2 (after fixing the problem described in https://issues.apache.org/jira/browse/LOG4J2-2806)
However it CAN'T be done easily with Logback, because the child loggers (and UUID-named logger is child of root logger) are held on a list...there's ONE test faling were I check what happens with a reference to LogService after pax-logging-api and pax-logging-log4j2 are refreshed while the test method is running...All findings will be at https://ops4j1.jira.com/browse/PAXLOGGING-311.regardsGrzegorz Grzybek
pt., 13 mar 2020 o 16:11 Grzegorz Grzybek <gr.g...@gmail.com> napisał(a):
Unfortunately I don't think there's much we can do...Once a Logger is created it will not be deleted until the LoggerContext it is associated with is deleted. Typically, this will only happen when the application is shut down or un-deployed. Each call to getLogger with the same logger name will return the same Logger instance.I even changed LoggerContext to use LoggerRegistry (log4j2) with org.apache.logging.log4j.spi.LoggerRegistry.WeakMapFactory), but this doesn't change anything - the created map uses weak key (strings - logger names), but the same key (string) is kept in a Logger instance - the value of WeakHashMap - this breaks WeakHashMap contract:Thus care should be taken to ensure that value objects do not strongly refer to their own keysMonica - which pax-logging backed are you using - Log4j2? Did you check a heapdump? How many actual different loggers do you create?In my test, I tried creating 1,000,000 loggers with unique names and used -Xmx128M. OOME (heap) happened after ~300K loggers created.The only change I needed in Pax Logging 1.11+ was change of org.ops4j.pax.logging.OSGIPaxLoggingManager#m_loggers to WeakHashMap.I don't think there's a need to reverse back the key-value order - especially in 1.11+.Is there a chance to analyze a heapdump of your application?regardsGrzegorz GrzybekregardsGrzegorz Grzybek
To view this discussion on the web visit https://groups.google.com/d/msgid/ops4j/27968583-d090-43a0-b963-12a923c31fd4%40googlegroups.com.
To unsubscribe from this group and stop receiving emails from it, send an email to ops4j+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ops4j/316e85a1-39de-47dd-b839-9d6be9f9660f%40googlegroups.com.
--
--
------------------
OPS4J - http://www.ops4j.org - op...@googlegroups.com
---
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 ops4j+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ops4j/e6783b83-bc0c-4d98-aae3-d28e72949c2b%40googlegroups.com.
To unsubscribe from this group and stop receiving emails from it, send an email to op...@googlegroups.com.
To unsubscribe from this group and stop receiving emails from it, send an email to ops4j+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ops4j/60e642dd-33d3-4249-beb4-87d2b65d7944%40googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ops4j/CAAdXmhr2H_PvGJPSHJU%2B0k8NoV9aWbvGdowQcrWio%2Bdks%3DgE6w%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ops4j/CAB8EV3RqgmqJEu5tCgiWVK%3Dk6ejcqvWtvTTdTiK%2BveRuLtQEYA%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ops4j/CAAdXmhoYZpbcW5jZg0FCqr4SSKNhA%2B-_SeCLERVrHw0S64tNNQ%40mail.gmail.com.
--
--
------------------
OPS4J - http://www.ops4j.org - op...@googlegroups.com
---
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 ops4j+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ops4j/731de33c-9f08-463c-8db5-c92c892fc42f%40googlegroups.com.
To unsubscribe from this group and stop receiving emails from it, send an email to op...@googlegroups.com.
To unsubscribe from this group and stop receiving emails from it, send an email to ops4j+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ops4j/a80b948c-a403-44bf-bb34-9e373c0d2f3c%40googlegroups.com.