Register / Login
Blog around the Campfire
When to use ThreadLocal in Java, thread-safety example
posted 2 years ago
variable is another way of achieving thread-safety in
. If a class, which is important but not thread-safe and at same time very expensive to create, it make lot of sense to only have limited number of instance of that variable and using
concept to share them between multiple threads. In this article, I have used
ThreadLocal variables to provide thread-safety to SimpleDateFormat
class. As most of Java programmer knows that
SimpleDateFormat is not thread-safe
and same time very expensive to create locally, by carefully wrapping them inside
can provide best of both world. By the way be careful, while using
variable in manged environment like
web and application server. Reckless use of
variable can create
memory leak in Java web application
. For example, storing an object loaded by web app classloader in
, may prevent that class and subsequently that classloader from being Garbage collected, which can create a memory leak in container.
SQL Query Interview Question
java.text.Format is not thread-safe
Error in log: ...have started a TimerThread named
Using "this" keyword in parent class thread safe?
I am connecting liferay communtiy edition 6.0.6 with postgresql 9.1 and using apache tomcat server6.