【发布时间】:2013-10-17 09:34:21
【问题描述】:
我有一堂课A:
@Service
public class A {
public void goX() {
System.out.println("goX");
try {
Thread.sleep(2000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
public void goY() {
System.out.println("goY");
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
还有一个 AOP 类 AOP:
@Aspect
@Service
class AOP {
@Around("execution(* com.test.A.goX(..))")
public void calExecTime(ProceedingJoinPoint proceedingJoinPoint) throws Throwable {
long t1 = System.currentTimeMillis();
proceedingJoinPoint.proceed();
long t2 = System.currentTimeMillis();
System.out.println(t2-t1);
}
}
然后我可以通过方法AOP.calExecTime()来计算A.goX()执行的时间。
我想要的是用同样的方法AOP.calExecTime() 计算A.goX() 和A.goY() 的时间,我不知道如何在@Around 注释中写东西。谁能帮帮我?非常感谢。
【问题讨论】:
标签: java annotations aspectj