1

I want to know how i can find a particular method is currently running,if it is currently running i don't want to execute another function.

Class myclass extending someclass{
  private void method A(){

  //somthing here
  }

  private void method B(){

  //somthing here
  }

  private void method C(){
   B();//don't want to call B if A is running 

  //somthing here
  }
}

boolean flag ia not working.I don't want static boolean flag.I am calling different function when orientation of mobile device changes but in one of four orientation i was to check whether a function is currently running or not.

Amrendra
  • 2,019
  • 2
  • 18
  • 36
  • did you tried setting a flag which gets initialized when A is running and resets to null when A's execution is over – gurvinder372 Apr 29 '13 at 05:18
  • What do you mean running? Do you mean another thread is running that method or simply that the method C was called from within method A? – tbkn23 Apr 29 '13 at 05:20
  • possible duplicate of [Getting the name of the current executing method](http://stackoverflow.com/questions/442747/getting-the-name-of-the-current-executing-method) – Pankaj Kumar Apr 29 '13 at 05:20
  • @Amrendra can you share the code that you have tried? – gurvinder372 Apr 29 '13 at 05:21
  • 1
    Are you sure you don't simply want to use a synchronization primitive (such as locking, a semaphore, etc)? – Patashu Apr 29 '13 at 05:22

2 Answers2

0

Check this link

Getting the name of the current executing method

also you can set a flag which gets initialized when A is running and resets to null when A's execution is over

Community
  • 1
  • 1
gurvinder372
  • 66,980
  • 10
  • 72
  • 94
0

You can try this

AtomicInteger aCount = new AtomicInteger(0);

private void A() {
    aCount.incrementAndGet();
    try {
        //
    } finally {
        aCount.decrementAndGet();
    }
}

private void B() {
}

private void C() {
    if (aCount.intValue() == 0) {
        B();
    }
}
Evgeniy Dorofeev
  • 133,369
  • 30
  • 199
  • 275