For an example, if we have some variable in run method, and
we created one or more threads. Does all threads will share
the same variable or a copy of variable is created for each
thread??



For an example, if we have some variable in run method, and we created one or more threads. Does a..

Answer / ranganathkini

No, each thread will have its own copy of the variable.

The reason is that run() is a method and any variable
declared inside a method is considered a local method and
its scope remains only within that method. If new thread
instances are spawned then each thread instances' run()
method will have their own copy of the variable.

Is This Answer Correct ?    3 Yes 0 No

Post New Answer

More Advanced Java Interview Questions

What is Servlet Filter And What does it work?

1 Answers   TCS,


How to implement dphibernate to activate lazy loading in Flex with java ?thanx in advance!

0 Answers  


how java is os independent language ?

3 Answers  


difference between  ejb,struts,hibernate,spring and jsp

0 Answers  


Is the ternary operator written x : y ? Z or x ? Y : z ?

0 Answers  






What is waiting state? In what ways a thread can enter into waiting state?

2 Answers   Wipro,


How will the struts know which action class to call when you submit a form?

6 Answers   HeadStrong,


Is there a guarantee of uniqueness for entity beans?

0 Answers  


What is the difference between the font and fontmetrics classes?

0 Answers  


What is the difference between Super and This Keyword?

4 Answers   HCL, TCS,


What is threadfactory?

0 Answers  


whats is mean by class.forName() whats the return type of class

3 Answers   SolutionNET,


Categories