i am having a class R implementing runnabale interface. it has an instance variable A with its getter and setter methods. i am creating a thread T using interface R. In the run() method of R i am creating a different thread T1 using different Runnable interface R1 Thread T will be in wait mode until thread t1 has completed. In run() method of R1 can i access the instance variable A using its getter method (provided R1 having R reference)
Can a thread access the instance variable of other thread which is in wait() mode?
The instance variables of a class belong to the instance of that class, not any particular thread. So you can access them from any thread, which thread created it is irrelevent. Where this becomes murky is when you're trying to keep state and data consistent across different threads which may be executing methods concurrently and may even have their own copies of a variable.
Originally posted by Edward Harned: Did you try it yourself?
You took the time to post the question, but did you run it with real values and see what happened?
Had you done that, then you wouldn't have posted this question.
That's a bit harsh, particularly when it comes to multithreading. Observing results does not directly translate to accurately understanding what caused the observations. After all, would you conclude that double-checked locking is safe if you observed it to be so, or would you go seek some other authority to confirm that it actually is safe and you just didn't happen to encounter the problem yet?