garydgregory commented on code in PR #419: URL: https://github.com/apache/commons-logging/pull/419#discussion_r3170563655
########## src/main/java/org/apache/commons/logging/jakarta/ServletContextCleaner.java: ########## @@ -0,0 +1,147 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.commons.logging.jakarta; + +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; + +import jakarta.servlet.ServletContextEvent; +import jakarta.servlet.ServletContextListener; + +import org.apache.commons.logging.LogFactory; + +/** + * This class is capable of receiving notifications about the undeployment of + * a webapp, and responds by ensuring that commons-logging releases all + * memory associated with the undeployed webapp. + * <p> + * In general, the WeakHashtable support added in commons-logging release 1.1 + * ensures that logging classes do not hold references that prevent an + * undeployed webapp's memory from being garbage-collected even when multiple + * copies of commons-logging are deployed via multiple class loaders (a + * situation that earlier versions had problems with). However there are + * some rare cases where the WeakHashtable approach does not work; in these + * situations specifying this class as a listener for the web application will + * ensure that all references held by commons-logging are fully released. + * </p> + * <p> + * To use this class, configure the webapp deployment descriptor to call + * this class on webapp undeploy; the contextDestroyed method will tell + * every accessible LogFactory class that the entry in its map for the + * current webapp's context class loader should be cleared. + * </p> + * + * @since 1.4.0 + */ +public class ServletContextCleaner implements ServletContextListener { + + private static final Class<?>[] RELEASE_SIGNATURE = { ClassLoader.class }; + + /** + * Constructs a new instance. + */ + public ServletContextCleaner() { + // empty + } + + /** + * Invoked when a webapp is undeployed, this tells the LogFactory + * class to release any logging information related to the current + * contextClassloader. + */ + @Override + public void contextDestroyed(final ServletContextEvent sce) { + final ClassLoader tccl = Thread.currentThread().getContextClassLoader(); Review Comment: I was going to do that initially but stopped myself. I think the simplest solution for now is to keep the `javax` and `jakarata` paths separate. If some subtle difference needs to be accounted for, then it can be dropped in the right class without concern of creating a regression in the other. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
