title: Java - execute method only once
body: <p>I have a simple problem:</p>
  
  <pre><code>Class A{
  
      B b;
  
      public void doSth{ 
           //This method should execute only once
           b.modify(); //calls doSth() again...
      }
  }
  </code></pre>
  
  <p>As the program runs, an instance of A is passed to B, and B calls doSth (as a callback for instance). <code>b.modify</code> makes B to call <code>A.doSth()</code> 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 <code>b.modify</code>.</p>
  
  <p>Any suggestions greatly appreciated.</p>