| 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: 5369
|
|
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: 5369
|
|
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: 5369
|
|
Thanks again Jose I think you have given your local drive's address AW here is JLS17.10 thanks a lot ..
|
 |
 |
|
|
subject: THREADS OPERATE ON THEIR OWN COPIES OF INSTANCE VARIABLES
|
|
|