我需要探究一个静态方法。但是无法探测方法调用。有人可以提供帮助吗?

我的Java代码:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

// CaseObject.java
package test;

public class CaseObject{

    private static int sleepTotalTime=0;

    public boolean execute(int sleepTime) throws Exception{
        System.out.println("sleep: "+sleepTime);
        sleepTotalTime+=sleepTime;
        Thread.sleep(sleepTime);
        return true;
    }

    public static boolean execute2(int sleepTime) throws Exception{
        System.out.println("sleep: "+sleepTime);
        sleepTotalTime+=sleepTime;
        Thread.sleep(sleepTime);
        return true;
    }
}

// Case2.java
package test;

import java.util.Random;

public class Case2 {

    public static void main(String[] args) throws Exception {
        Random random = new Random();
        boolean result = true;
        while (result) {
            result = CaseObject.execute2(random.nextInt(1000));
            Thread.sleep(1000);
        }
    }

}


我的btrace脚本
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

// TraceMethodArgsAndReturn2.java
import static com.sun.btrace.BTraceUtils.*;
import com.sun.btrace.annotations.*;

@BTrace public class TraceMethodArgsAndReturn2{
    @OnMethod(
            clazz="test.CaseObject",
            method="execute2",
            location=@Location(Kind.RETURN)
    )
    public static void traceExecute(@Self test.CaseObject instance,int sleepTime,@Return boolean result){
        println("call CaseObject.execute2");
        println(strcat("sleepTime is:",str(sleepTime)));
        println(strcat("sleepTotalTime is:",str(get(field("test.CaseObject","sleepTotalTime"),instance))));
        println(strcat("return value is:",str(result)));
    }
}


我这样运行
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
./btrace/bin/btrace -cp / tmp / a / target / classes / 8477 ./btrace/TraceMethodArgsAndReturn2.java

最佳答案

好的,我发现了问题... @Self不应该使用。

09-11 18:38