I'm still confused about the concept of ThreadLocal. I read the JavaDoc and other related questions posted here, but the jargon used and all this did not help me.
I kind of understand the idea of โโThreadLocal, that is, each thread has its own copy of the variable. So ... how does this distinguish it from ... creating a new variable every time?
For example, using DateFormatter as an example:
public void convertDate(String date)
{
DateFormatter df = new SimpleDateFormatter(...);
....
}
public void convertDate(String date)
{
DateFormatter df = threadLocal.get();
....
}
How is the first different from the second if everything that the second does just returns a new copy of the variable?
Thanks.
source
share