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??

Answer Posted / 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       View All Answers


Please Help Members By Posting Answers For Below Questions

Define the remote object implementation?

2228


What must a class do to implement an interface?

823


Explain the steps in details to load the server object dynamically?

4834


Why a component architecture for the java platform?

825


How are the elements of a cardlayout organized?

831


To identify IDL language what mapping mechanism is used?

3689


What is a tasks priority and how is it used in scheduling?

817


How will you pass parameters in RMI? Why do you serialize?

956


Name three subclasses of the component class?

890


Describe, in general, how java's garbage collector works?

791


difference between  ejb,struts,hibernate,spring and jsp

2615


What class is the top of the awt event hierarchy?

866


Is there a guarantee of uniqueness for entity beans?

794


What are the purpose of introspection?

975


Can I use multiple html form elements with the same name?

850