When we have a static method which is not synchronized, it is possible that two or more threads would access the same method at the same time. At this point of time, are there going to be two copies of the same method - one for each thread?If not, what would happen to the local variables? Or is it that each thread would have its own stack where local variables would be placed?If so, what would happen to the static variables? Any light on this is appreciated.
The local variables for any method, static or not, are held on the execution stack of the thread that's executing it. If a hundred threads call a method simultaneously, then there will be a hundred "copies" of the local variables. On the other hand, there is a copy of a class's member variables in each instance of the class, and there is just a single copy of the static variables for a class.