Frage

I have a thread with this run method:

  public void run(){    
    MAPTable t1 = new MAPTable();
    t1.init();
    while(true){
       try {       
           t1.refresh();
       } catch (UnknownHostException e) {
           e.printStackTrace();
       }
       try {
           sleep(10000);
       } catch (InterruptedException e) {
           e.printStackTrace();
       }            
    }        
  }

How can i have i trace of all the functions executed by this thread, NOTE that init() an refresh() methods can call many others functions based on many external conditions.

I have tried to make a NullPointerException or placed one of those lines of code referenced here in the middle of the run() method, but i have always just the last trace which is the run() method (the same line i have used to print the trace).

 Thread.currentThread().getStackTrace()

or

 for (StackTraceElement ste : Thread.currentThread().getStackTrace()) {
    System.out.println(ste + "\n");
 }

or

Thread.dumpStack()

PS: I'm not so familiar with the debugger and i don't know if this can be done with it.

War es hilfreich?

Lösung

You may find some useful information in http://blog.zvikico.com/2007/11/five-ways-for-t.html

I think some of the profilers may be able to provide options to generate all call traces.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top