ThreadLocalLeakPreventionListener (Apache Tomcat 11.0.21 API Documentation)
Description: declaration: package: org.apache.catalina.core, class: ThreadLocalLeakPreventionListener

# Class ThreadLocalLeakPreventionListener

java.lang.Object
org.apache.catalina.core.FrameworkListener
org.apache.catalina.core.ThreadLocalLeakPreventionListener

All Implemented Interfaces:
  `ContainerListener, LifecycleListener`

public class ThreadLocalLeakPreventionListener extends FrameworkListener
A `LifecycleListener` that triggers the renewal of threads in Executor pools when a `Context` is being stopped to avoid thread-local related memory leaks.

Note : active threads will be renewed one by one when they come back to the pool after executing their task, see `ThreadPoolExecutor`.afterExecute().

This listener must only be nested within `Server` elements.

- ## Field Summary

  Fields
  Modifier and Type
  Field
  Description
  `protected static final StringManager`
  `sm`
  The string manager for this package.

  ### Fields inherited from class FrameworkListener

  `contextListeners`

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `ThreadLocalLeakPreventionListener()`

- ## Method Summary

  Modifier and Type
  Method
  Description
  `void`
  `containerEvent(ContainerEvent event)`
  Acknowledge the occurrence of the specified event.
  `protected LifecycleListener`
  `createLifecycleListener(Context context)`
  Create a lifecycle listener which will then be added to the specified context.
  `void`
  `lifecycleEvent(LifecycleEvent event)`
  Listens for `LifecycleEvent` for the start of the `Server` to initialize itself and then for after_stop events of each `Context`.

  ### Methods inherited from class FrameworkListener

  `processContainerAddChild, processContainerRemoveChild, registerContextListener, registerListenersForEngine, registerListenersForHost, registerListenersForServer`

  ### Methods inherited from class Object

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

- ## Field Details

  - ### sm

    protected static final StringManager sm
    The string manager for this package.

- ## Constructor Details

  - ### ThreadLocalLeakPreventionListener

    public ThreadLocalLeakPreventionListener()

- ## Method Details

  - ### lifecycleEvent

    public void lifecycleEvent(LifecycleEvent event)
    Listens for `LifecycleEvent` for the start of the `Server` to initialize itself and then for after_stop events of each `Context`.
    Specified by:
      `lifecycleEvent` in interface `LifecycleListener`
    Overrides:
      `lifecycleEvent` in class `FrameworkListener`
    Parameters:
      `event` - LifecycleEvent that has occurred

  - ### containerEvent

    public void containerEvent(ContainerEvent event)
    Description copied from interface: `ContainerListener`
    Acknowledge the occurrence of the specified event.
    Specified by:
      `containerEvent` in interface `ContainerListener`
    Overrides:
      `containerEvent` in class `FrameworkListener`
    Parameters:
      `event` - ContainerEvent that has occurred

  - ### createLifecycleListener

    protected LifecycleListener createLifecycleListener(Context context)
    Description copied from class: `FrameworkListener`
    Create a lifecycle listener which will then be added to the specified context.
    Specified by:
      `createLifecycleListener` in class `FrameworkListener`
    Parameters:
      `context` - the associated Context
    Returns:
      the lifecycle listener