DIR Return Create A Forum - Home
---------------------------------------------------------
ifaq
HTML https://ifaq.createaforum.com
---------------------------------------------------------
*****************************************************
DIR Return to: Common operating systems related questions
*****************************************************
#Post#: 31--------------------------------------------------
What does a thread share with it main process?
By: avinash.srin Date: July 4, 2012, 3:00 am
---------------------------------------------------------
Each thread is separated, so that local variables in the methods
that the thread is executing are separate for different threads.
These local variables are completely private; there is no way
for one thread to access the local variables of another thread.
If two threads happen to execute the same method, each thread
gets a separate copy of the local variables of that method.
Objects and their instance variables can be shared between
threads in a Java program, and sharing these objects is much
easier between threads of a Java program than sharing data
objects between processes in most operating systems. In fact,
the ability to share data objects easily between threads is
another reason why programming with threads is so useful. But
Java threads cannot arbitrarily access each others data objects:
they need permission to access the objects, and one thread needs
to pass the object reference to the other thread.
Static variables are the big exception to this analogy: they are
automatically shared between all threads in a Java program.
*****************************************************