4. 虚拟机性能监控和故障处理工具

1.JDK命令行工具:windows下可以使用,linux也可以使用

https://blog.csdn.net/WinWill2012/article/details/46364923

2.Java VisualVM:在Java bin 目录下 直接打开即可

测试trace 插件

测试用例:

脚本:

/* BTrace Script Template */

import com.sun.btrace.annotations.*;

import static com.sun.btrace.BTraceUtils.*;

@BTrace

public class TracingScript {

/* put your code here */

@OnMethod(

clazz="y190225.BTreeTest",

method="add",

location=@Location(Kind.RETURN)

)

public static void func(@Self y190225.BTreeTest instance, int a, int b, @Return int result) {

println("调用堆栈:");

jstack();

println(strcat("方法参数A:",str(a)));

println(strcat("方法参数B:",str(b)));

println(strcat("方法结果:",str(result)));

}

}

Java:

public class BTreeTest {

public int add(int a, int b) {

return a + b;

}

public static void main(String[] args) throws InterruptedException {

BTreeTest bTreeTest = new BTreeTest();

//BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));

for (int i = 0; i < 10; i++) {

Thread.sleep(10000);

int a = (int) Math.round(Math.random() * 1000);

int b = (int) Math.round(Math.random() * 1000);

System.out.println(bTreeTest.add(a,b));

}

}

}

猜你喜欢

转载自blog.csdn.net/qq_39304216/article/details/87966752