If the ThreadLocal variable is not cleared, what will happen?

defined a threadlocal variable in the class to support some instances. setting up and getting a recursive method. To some extent, I cannot clear the threadlocal variable when the request is complete (I have analyzed all the other ways. I cannot clear threadlocal).

My question is: if I did not clear the threadlocal variable for each request, what will happen? What are the implications?

+5
source share
3 answers

The javadoc says:

after the stream disappears, all its copies of local-local instances are subject to garbage collection (if other links to these copies exist).

, HashTable, . - . , .

, . : , , GC, VM .

:

  • , concurrency. , , , . , concurrency.

  • , , " " . .

  • , thread local "" , . .

+9

, ThreadLocal, ( ) .

, .

, .

+2

You have a memory leak, and ThreadLocal may already be installed the next time you call the code. ThreadLocals is a little smell of imo code.

0
source

All Articles