我有一堂课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);
}
}
然后我可以计算A.goX()方法执行所需的时间AOP.calExecTime()。
我想要的是通过相同的方法计算两者A.goX()的A.goY()AOP.calExecTime()时间,我不知道如何在@Around注释中写东西。谁能帮帮我?非常感谢。