| Author |
Are Local variables Thread Safe?
|
Suni Kr
Greenhorn
Joined: Oct 14, 2004
Posts: 11
|
|
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.
|
SCJP,SCWCD,SCBCD
|
 |
Nathaniel Stoddard
Ranch Hand
Joined: May 29, 2003
Posts: 1258
|
|
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.
|
Nathaniel Stodard<br />SCJP, SCJD, SCWCD, SCBCD, SCDJWS, ICAD, ICSD, ICED
|
 |
Sanjeev Kaushik
Ranch Hand
Joined: Aug 01, 2002
Posts: 105
|
|
|
Simple Funda - each thread has their own copy of local variables, hence threadsafe
|
Sanjeev Kaushik
|
 |
 |
|
|
subject: Are Local variables Thread Safe?
|
|
|