• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

THREADS OPERATE ON THEIR OWN COPIES OF INSTANCE VARIABLES

 
Deepali Pate
Ranch Hand
Posts: 114
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"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
Posts: 2120
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
R K Singh
Ranch Hand
Posts: 5382
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Threads do share instance variable.
They dont have their own copies of member var.
Plz correct me if I am wrong
HTH
 
R K Singh
Ranch Hand
Posts: 5382
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2120
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 5382
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic