Hi,
I am still confused of the concept of ThreadLocal. I have read the JavaDoc, and other related questions posted around here, but the jargons used and all didn't help me much.
I kind of get the idea of ThreadLocal, that is, each thread has its own copy of the variable. So...how does this make it different from say...constructing the new variable everytime?
For example, using DateFormatter as the example:
public void convertDate(String date)
{
// Contruct new date formatter for every invocation of the method.
DateFormatter df = new SimpleDateFormatter(...);
....
}
public void convertDate(String date)
{
// Getting date formatter from threadlocal.
DateFormatter df = threadLocal.get();
....
}
How is the first different from the second one if the all the second one does is just returning a new copy of the variable?
Thanks.