Skip to content

Remove ThreadLocals when putting the thread back to the pool #25639

@dmatej

Description

@dmatej

Description

The org.glassfish.web.loader.ReferenceCleaner reports leaking ThreadLocals when WebAppClassLoader closes, but it would be probably more secure if thread pools would do that by default when they are putting used thread back to the pool.

The feature should be enabled by default, but it should be possible to disable it too (to allow original behavior for legacy applications).

Investigate also other options using the reflection less.

Example where it could be useful:

mvn clean install -Ptck -pl :glassfish-external-tck-microprofile-rest-client

When you open server.log, you notice warnings from WebAppClassloader complaining about WireMock leaking Thread locals.

[2025-09-09T20:21:06.263605+02:00] [GF 7.1.0-SNAPSHOT] [SEVERE] [AS-WEB-UTIL-00016] [org.glassfish.web.loader.ReferenceCleaner] [tid: _ThreadID=139 _ThreadName=admin-listener(3)] [levelValue: 1000] [[
  The web application [/InvokeWithJsonBProviderTest] created a ThreadLocal with key of [class com.github.tomakehurst.wiremock.client.WireMock$1 (toString: com.github.tomakehurst.wiremock.client.WireMock$1@56af2b76)] and a value of [class com.github.tomakehurst.wiremock.client.WireMock (toString: com.github.tomakehurst.wiremock.client.WireMock@44779b95)] 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.]]


Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions