ThreadLocal in a pooled executor is a leak and a data leak

A pooled thread outlives the request that set the value. The next task on that thread inherits it - so the entry never becomes garbage, and one user's tenant or principal is read by another user's request.

Full code & output

This topic is available to PRO members.

Sign in Create a free account

Run this yourself in the Online Java Compiler, spin up a live REST API in the API Sandbox, or practise with Java interview questions.

Published 2026-08-25