File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes THREADS OPERATE ON THEIR OWN COPIES OF INSTANCE VARIABLES Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "THREADS OPERATE ON THEIR OWN COPIES OF INSTANCE VARIABLES" Watch "THREADS OPERATE ON THEIR OWN COPIES OF INSTANCE VARIABLES" New topic
Author

THREADS OPERATE ON THEIR OWN COPIES OF INSTANCE VARIABLES

Deepali Pate
Ranch Hand

Joined: Mar 20, 2002
Posts: 114
"NORMALLY THREADS OPERATE ON THEIR OWN COPIES OF INSTANCE VARIABLES, NOT ORIGINALS"
Is this TRUE or FAlSE?
I understand that threads share the same data space and hence tehy are light weight.
Please explain
Jose Botella
Ranch Hand

Joined: Jul 03, 2001
Posts: 2120
I think it's true.
from the chapter 17 of JLS

Each thread has a working memory, in which it may keep copies of the values of variables from the main memory that is shared between all threads. To access a shared variable, a thread usually first obtains a lock and flushes its working memory. This guarantees that shared values will thereafter be loaded from the shared main memory to the threads working memory. When a thread unlocks a lock it guarantees the values it holds in its working memory will be written back to the main memory.

Does anybody know a reason for not saying the same about static fields?
[ July 01, 2002: Message edited by: Jose Botella ]

SCJP2. Please Indent your code using UBB Code
R K Singh
Ranch Hand

Joined: Oct 15, 2001
Posts: 5371
Threads do share instance variable.
They dont have their own copies of member var.
Plz correct me if I am wrong
HTH


"Thanks to Indian media who has over the period of time swiped out intellectual taste from mass Indian population." - Chetan Parekh
R K Singh
Ranch Hand

Joined: Oct 15, 2001
Posts: 5371
Hi Jose
But here it is not talking abt synchronization, I mean locking of object.
Normally I think thread do not keep there own copy.
Plz CMIW
Jose Botella
Ranch Hand

Joined: Jul 03, 2001
Posts: 2120
Hi Ravish.
In the JLS example given at 17.10
they talk about working copies even when no synchronized methods are called.
R K Singh
Ranch Hand

Joined: Oct 15, 2001
Posts: 5371
Thanks again Jose
I think you have given your local drive's address
AW here is JLS17.10
thanks a lot ..
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: THREADS OPERATE ON THEIR OWN COPIES OF INSTANCE VARIABLES