Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3978420
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T05:02:43+00:00 2026-05-20T05:02:43+00:00

In short – tomcat uses a thread pool, so threads are reused. Some libraries

  • 0

In short – tomcat uses a thread pool, so threads are reused. Some libraries use ThreadLocal variables, but don’t clean them up (using .remove()), so in fact they return “dirty” threads to the pool.

Tomcat has new features of detecting these things on shutdown, and cleaning the thread locals. But it means the threads are “dirty” during the whole execution.

What I can do is implement a Filter, and right after the request completes (and the thread is returned to the pool), clean all ThreadLocals, using the code from tomcat (the method there is called checkThreadLocalsForLeaks).

The question is, is it worth it? Two pros:

  • preventing memory leaks
  • preventing undeterministic behaviour by the libraries, which assume the thread is “fresh”

One con:

  • The solution uses reflection, so it’s potentially slow. All reflection data (Fields) will be cached, of course, but still.

Another option is to report the issue to the libraries that don’t clean their thread locals.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T05:02:44+00:00Added an answer on May 20, 2026 at 5:02 am

    I would go through the route of reporting the issue to the library developers for 2 reasons:

    • It will help to other people who want to use the same library, but lack the skills / time to find such a HORRIBLE memory leak.
    • To help the developers of the library to build a better product.

    Honestly, I’ve never seen this type of error before and I think it’s an exception rather than something that we should guard as it happens often. Could you share on which library you’ve seen this behaviour?

    As a side note, I wouldn’t mind enabling that filter in the development / test environment and logging a critical error if a ThreadLocal variable is still attached.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Short version: assuming I don't want to keep the data for long, how do
Short Version: When I've created a Channel using ChannelFactory on a client which uses
Short of inserting a try/catch block in each worker thread method, is there a
Short Question: What's the best date format to use in SQL Server? Long Explanation:
Short question : I know how to draw text on a wx.Bitmap, but how
Short question: How can I use createLink in a Filter? I'm getting error: No
Short question but for me its difficult to understand. Why exactly does ePoll scale
Short version: What kind of escape sequence can one use to search for unicode
Short question. I just got a dll I'm supposed to interface with. Dll uses
Short but simple? I have an edit.ascx is in the shared folder. I call

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.