I need to ensure that a particular method execution time is less than the specified value. I would like to do some thing like the following
@Around("execution(* com.foo.bar.executeTask2(..))" + " && someExternalParams(500)")
@Around("execution(* com.foo.bar.executeTask(..))" + " && someExternalParams(5)")
public void checkSLA(ProceedingJoinPoint joinPoint, int maxtime) throws Throwable {
//get staarttime
joinPoint.proceed();
// get endtime
if(endtime - starttime > maxtime)
System.out.println("Task took longertime");
}
How can I achieve this with Spring AOP. One solution is to read the maxtime from file. Any thoughts?
Hi you can make a
@SLAannotation and read that value from it in your aspect. You must obviously change advise to match that annotation and mark all your methods with@SLAannotation.It’s little bit different from your approach but I think it’s even better to make annotation for this kind of aspect. This way you don’t have to update your pointcut every time you want handling new method. Just add annotation to this method. See example below.
Annotation:
Aspect:
Usage: