ThreadLocal Memory Leak Warnings on Shutdown

Last modified by superadmin on 2026/11/25 21:30

Some XWiki components leave ThreadLocal values behind when undeployed, which stopping the whole Tomcat server instead avoids.

Explanation

When stopping XWiki on Tomcat, you may encounter log messages similar to the following:

SEVERE [Thread-794]
org.apache.catalina.loader.WebappClassLoaderBase.checkThreadLocalMapForLeaks
The web application [...] created a ThreadLocal with key of type [java.lang.ThreadLocal]
(value [java.lang.ThreadLocal@1125fc78]) and a value of type [...] (value [...]) but failed to remove it when the web application was stopped.
Threads are going to be renewed over time to try and avoid a probable memory leak.

Cause

This is a known limitation of XWiki related to the cleanup of some ThreadLocal variables. Some XWiki components use ThreadLocal variables that are not fully cleaned up when the XWiki web application is undeployed. This can trigger Tomcat memory leak warnings during shutdown or undeployment.

Solution

  • Stop XWiki by stopping the entire Tomcat server instead of undeploying only the XWiki web application.
  • Avoid stopping or redeploying XWiki using the Tomcat Manager application.
  • Restart Tomcat completely when redeploying or upgrading XWiki.

Stopping the Tomcat JVM completely ensures that all threads and ThreadLocal variables are properly cleaned up, preventing potential memory leaks.

Related

Get Connected