BTrace拦截输入参数及返回值_JAVA_编程开发_程序员俱乐部

中国优秀的程序员网站程序员频道CXYCLUB技术地图
热搜:
更多>>
 
您所在的位置: 程序员俱乐部 > 编程开发 > JAVA > BTrace拦截输入参数及返回值

BTrace拦截输入参数及返回值

 2012/3/14 9:58:41  buzhucele  程序员俱乐部  我要评论(0)
  • 摘要:服务端类:packagetest;publicclassBTraceServer{publicStringsayHello(inti){return"参数"+i;}publicstaticvoidmain(String[]args)throwsInterruptedException{BTraceServerbt=newBTraceServer();inti=0;while(true){System.err.println(bt.sayHello(i++));Thread.sleep(1000
  • 标签:
服务端类:
package test;

public class BTraceServer {

	public String sayHello(int i) {
		return "参数" + i;
	}

	public static void main(String[] args) throws InterruptedException {
		BTraceServer bt = new BTraceServer();
		int i = 0;
		while (true) {
			System.err.println(bt.sayHello(i++));
			Thread.sleep(1000);
		}
	}

}


客户端类:
package test;

import com.sun.btrace.BTraceUtils;
import com.sun.btrace.annotations.BTrace;
import com.sun.btrace.annotations.Kind;
import com.sun.btrace.annotations.Location;
import com.sun.btrace.annotations.OnMethod;
import com.sun.btrace.annotations.Return;
import com.sun.btrace.annotations.Self;

@BTrace
public class BTraceTest {
	@OnMethod(clazz="test.BTraceServer", method="sayHello",
		     location=@Location(Kind.RETURN))
	public static void onSayHello(@Self BTraceServer s, int param, @Return String ret){
		BTraceUtils.print(param);
		BTraceUtils.println(ret);
	}
			
}


1、将服务端类打成jar包;
2、btrace执行btrace -classpath D:\doc\btrace\btrace-bin\build\test.jar 【PID】 BTraceTest.java
  • 相关文章
发表评论
用户名: 匿名