I have to clear my concept and so please let me know if I am wrong anywhere.
Memory storage - We have stack and heap. Object and instance variables are stored in heap and local variables are stored in stack. also the refrences to the objects are stored in stack.
Thread concept - Say we have method and we have local variable x decalred inside the method. Thread 1 invoke the method and sets the value of variable x as 10 and thread2 invoke the method and sets the variable x as 12.
Question: Will we have two stack for two threads having variable x in both with value 10 and 12 correspondingly.
I mean one stack will have x=10 and other stack will have x=12
Answer for this will help me a lot in understanding the concept deeper.
Yes, each thread has its own completely different stack. Every time a method is called -- on the same thread, or on different threads -- space is reserved for a new set of local variables which is completely independent of any other set.