Skip to content

Instantly share code, notes, and snippets.

@LeoHeo
Last active October 28, 2018 03:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save LeoHeo/db1a6cc9a0106f3a099cd2d494c1b904 to your computer and use it in GitHub Desktop.
Save LeoHeo/db1a6cc9a0106f3a099cd2d494c1b904 to your computer and use it in GitHub Desktop.
@Documented
@Retention(RetentionPolicy.CLASS) // default CLASS -> SOURCE, RUNTIME으로 변경할 필요 없음
@Target(ElementType.METHOD)
public @interface PerformaceLogging {
}
@Component
@Aspect
public class PerformanceAspect {
@Around("@annotation(PerformaceLogging)") // bean으로 설정하는 방법도 있다.
public Object logPeformace(ProceedingJoinPoint pjp) throws Throwable {
long begin = System.currentTimeMills();
Object returnProceed = pjp.proceed();
System.out.println((System.currentTimeMillis() - begin));
return returnProceed;
}
}
@Service
public class TestService {
@PerformaceLogging // 필요한 method에 annotation을 달아준다.
public String test2() {
try {
Thread.sleep(2);
} catch (InterruptedException e) {
e.printStackTrace();
}
return "test";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment