java - Do variables/flags can be affected by another thread on a non-synchronized method? -


for example have non-synchronized method this:

public void nonsynchronized(){      boolean flag = false;       if(/*some condition*/){           flag = true;      }       //more line of codes here        if(flag == true){            //do here - let's line 33.      }  } 

what if first thread executes method sets flag true, , before executing line 33 thread executes method resets variable flag false, first thread still execute line 33?

your flag local variable. each thread gets own copy on stack. don't interfere each-other @ all. can happen shared state, i.e. things on heap, i.e. fields of object.


Comments