I have a simple problem:
Class A{
B b;
public void doSth{
//This method should execute only once
b.modify(); //calls doSth() again...
}
}
As the program runs, an instance of A is passed to B, and B calls doSth (as a callback for instance). b.modify makes B to call A.doSth() again, which will infinite sequence of calls. What I want to achieve is this: I want to execute doSth() once, modify B, then upon next execution somehow stop the chain of inifinite calls and do not execute b.modify.
Any suggestions greatly appreciated.
Add a state flag to your class:
Use
volatileif multiple threads are in play.