Server/Java

Java) AOP - TimeTrace 시간측정

Juzdalua 2022. 11. 16. 15:37
@Aspect
@Component
public class TimeTraceAop {

  @Around("execution(* jun.studyspring..*(..))")
  public Object execure(ProceedingJoinPoint joinPoint) throws Throwable{
    long start = System.currentTimeMillis();
    System.out.println("START: "+joinPoint.toString());
    try {
      Object result = joinPoint.proceed();
      return result;
    } catch (Exception e) {
      // TODO: handle exception
    } finally{
      long finish = System.currentTimeMillis();
      long timeMs = finish - start;
      System.out.println("END: "+joinPoint.toString());
      System.out.println("timeMs: "+timeMs);
    }
  }

}