JLS
17.4.1 Shared Variables
Memory that can be shared between threads is called shared memory or heap memory.
All instance fields, static fields and array elements are stored in heap memory.
"If the facts don't fit the theory, get new facts" --Albert Einstein
Hunter McMillen wrote:You have declared testConstant as static, by default static members are shared by all threads in Java.
JLS
17.4.1 Shared Variables
Memory that can be shared between threads is called shared memory or heap memory.
All instance fields, static fields and array elements are stored in heap memory.
It is not a case of "easily shared". There is only one copy of each static member. If that member is passed to a thread, then it is passed. If it is passed to two threads, then it is passed to two threads. It is automatically and implicitly shared, not "easily". It is a bit like being out in the desert and having one water bottle. You might find it difficult to share the water bottle, but if anybody drinks from a water bottle, then that one bottle is shared.Uditha Perera wrote: . . . Static members are easily shared. . . .
Campbell Ritchie wrote: Objects are "shared" if you share them...
Campbell Ritchie wrote:You can share a singleton if you so wish, but that wasn't what I meant. I meant that the programmer shares objects. If you tell two threads to use the same objet, then you are sharing the one object between the two threads. In this case "share" has the same meaning it has in common English (look for "verb").
Popeye has his spinach. I have this tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
|