Why are local variables always thread safe?
Local variables are stored on the Thread calling stack. They are NOT shared between different calling threads. This is true in almost any programming languages, unless you declare the local variable as static such as in c/c++/VB, and then it is shared. However, Java does not allow that to happen. It does not matter it is static method or instance method. However, be cautious when your method modifies something else which is not local. That is when synchronized keyword needs to be kicked in. There is one thing in Java easily causes confusion. Java objects created local are not stored on thread calling stacks. They are always on the heap, only the local references are stored on the calling stack. If you make those objects available outside the local range, it will become thread unsafe. For example, if you store it in to the HttpSession, it is not thread safe any more.This is very different than c++ local objects, such as Object o; which is truely local. The Java object created local is e