Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Are Local variables Thread Safe?  RSS feed

 
Suni Kr
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi everyone,
I know that variables declared inside a service method(local variables) are thread safe. Can some one give me an example and explain how are the variables thread safe.

Thank you,
Suni.
 
Nathaniel Stoddard
Ranch Hand
Posts: 1258
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Simply put, there's just nobody else out there that has access to the variable once you've defined it locally.

Now, if you did something crazy like telling everybody else (threads) in your program about "o", then you would have a possible synchronization issue. But until that happens, local variables are nothing to worry about.
 
Sanjeev Kaushik
Ranch Hand
Posts: 105
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Simple Funda - each thread has their own copy of local variables, hence threadsafe
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!