Restricting method execution from other class method <p>Somebody asked me this question and I am not able to find out the solution, I have a class <code>A</code> with method <code>a1</code> and <code>a2</code>:</p> <p><code>Class A {a1() a2()}</code>:</p> <p>and a class <code>B</code> with method <code>b1</code> and <code>b2</code>:</p> <p><code>Class B {b1() b2()}</code></p> <p>Considering multithreading environment i want to stop execution of b1 when a1 is called and same applies for b2 and a2. Both the objects are independent. Is this possible? </p>