File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
A friendly place for programming greenhorns!
Big Moose Saloon
Register / Login
Win a copy of
Head First Android
this week in the
Blog around the Campfire
When to use ThreadLocal in Java, thread-safety example
Joined: Oct 15, 2010
Nov 18, 2013 07:22:54
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
Don't get me started about those stupid
subject: When to use ThreadLocal in Java, thread-safety example
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.
All times are in JavaRanch time: GMT-6 in summer, GMT-7 in winter
| Powered by
Copyright © 1998-2015