ServletContextCleaner (Apache Commons Logging 1.4.0 API)
Description: declaration: package: org.apache.commons.logging.jakarta, class: ServletContextCleaner

Package org.apache.commons.logging.jakarta

# Class ServletContextCleaner

java.lang.Object
org.apache.commons.logging.jakarta.ServletContextCleaner

All Implemented Interfaces:
  `jakarta.servlet.ServletContextListener`, `EventListener`

public class ServletContextCleaner extends Object implements jakarta.servlet.ServletContextListener
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.

In general, we ensurs 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 this 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.

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.

Since:
  1.4.0

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `ServletContextCleaner()`
  Constructs a new instance.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `void`
  `contextDestroyed(jakarta.servlet.ServletContextEvent sce)`
  Invoked when a webapp is undeployed, this tells the LogFactory class to release any logging information related to the current contextClassloader.
  `void`
  `contextInitialized(jakarta.servlet.ServletContextEvent sce)`
  Invoked when a webapp is deployed.

  ### Methods inherited from class java.lang.Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Constructor Details

  - ### ServletContextCleaner

    public ServletContextCleaner()
    Constructs a new instance.

- ## Method Details

  - ### contextDestroyed

    public void contextDestroyed(jakarta.servlet.ServletContextEvent sce)
    Invoked when a webapp is undeployed, this tells the LogFactory class to release any logging information related to the current contextClassloader.
    Specified by:
      `contextDestroyed` in interface `jakarta.servlet.ServletContextListener`

  - ### contextInitialized

    public void contextInitialized(jakarta.servlet.ServletContextEvent sce)
    Invoked when a webapp is deployed. Nothing needs to be done here.
    Specified by:
      `contextInitialized` in interface `jakarta.servlet.ServletContextListener`