I am learning Java multi threading and I read the following statement :
Local variables are always thread safe. Keep in mind though, that the object a local variable points to, may not be so. If the object was instantiated inside the method, and never escapes, there will be no problem. Just because you assign a shared object to a local reference, does not mean that object automatically becomes thread safe.
public class SimpleHttpServlet extends HttpServlet {
protected void Test() {
// How can `object' become not thread safe
SomeClass object= new SomeClass ();
}
}
In this example how can object
become not thread safe ?
Can you please explain with an example a scenario where local variable can be not thread safe and why ?