Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

5
  • Please add an even stronger emphasis to your third paragraph to state that local variables that are exposed to other threads or long-living objects will no longer be confined. Thus, the claim quoted from OP's book is very dubious. Commented Jul 31, 2012 at 5:49
  • 4
    @rwong: It is impossible to expose a local variable to another thread iin a way that would be problematic. Variables only contain primitives or references. Objects live on the heap. Commented Jul 31, 2012 at 7:31
  • @MichaelBorgwardt Lets take two cases separately say the variable contains a primitive which is case A and say the variable contains a reference which is case B . Since primitives are passed by value , the local variables are indeed thread safe but what about references . They can be passed around ? Why do you say it is impossible ? Commented Jul 31, 2012 at 8:17
  • 2
    @Geek: Because the variable and the object it refers to are two separate and different things that should not be confused when talking at this level of detail. A local variable cannot be exposed to a different thread. Objects certainly can. Commented Jul 31, 2012 at 11:32
  • @MichaelBorgwardt I see what you are saying.Thanks for the clarification. Commented Jul 31, 2012 at 11:41