资源:
package net.andrewewhite.aspects;
import java.util.ArrayList;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Around;
@Aspect
public class SocketProfiler {
@Around("call(* java.net.Socket.connect(..)) || execution(* java.net.Socket.connect(..))")
public void SocketRead(ProceedingJoinPoint joinPoint) throws Throwable {
long time=0;
Object rt=null;
time= System.nanoTime();
joinPoint.proceed();
time=(System.nanoTime()-time)/1000;
com.profile.Profiler.socketRead.add(time);
}
}
aop.xml
<aspectj>
<aspects>
<aspect name="net.andrewewhite.aspects.SocketProfiler"/>
</aspects>
<weaver options="-verbose -Xset:weaveJavaxPackages=true -Xset:weaveJavaPackages=true">
</weaver>
</aspectj>
虚拟机参数
-javaagent:D:\tools\aspectJn\lib\aspectjweaver.jar (on eclipse ide)
如果我尝试编织对 system.out.println 的调用,它会起作用。但是当我尝试 Java.net.Socket 时,它没有。任何有关的帮助表示赞赏。