Originally posted by John McDonald:
I start learning ThreadLocal. I have basic knowledge that is a separate thread to hold a separate value but I don't know if there its practical usage. Could you explain it? Is ThreadLocal useful?
But if I change the initialValue method to be:
protected synchronized Object initialValue()
{
System.out.println("New local thread + " + getName());// + " client Number " + id);
return new Client(++clientNum ;
}
Then output is:
New local thread + Thread-0
New local thread + Thread-1
Thread Thread-1 has client Client[1]
Thread Thread-0 has client Client[1]
Could someone show me why?
Originally posted by John McDonald:
Thank you very much for a quick reply. Can you point out the different outcome when I just changed the way I input initial value to Client object?
"I'm not back." - Bill Harding, Twister
Consider Paul's rocket mass heater. |