0 votes
in JAVA by
What is a thread local variable in Java?

1 Answer

0 votes
by

Thread-local variables are variables confined to a thread, its like thread's own copy which is not shared between multiple threads. Java provides a ThreadLocal class to support thread-local variables. It's one of the many ways to achieve thread-safety. Though be careful while using thread local variable in manged environment e.g. with web servers where worker thread out lives any application variable. Any thread local variable which is not removed once its work is done can potentially cause a memory leak in Java application.

Related questions

0 votes
asked May 5, 2021 in JAVA by SakshiSharma
+1 vote
asked Oct 17, 2020 in JAVA by rahuljain1
...