Performance: @Around advice for full control
This affects the runtime execution speed and responsiveness of Spring Boot applications by intercepting method calls.
@Around("execution(* com.example..*(..))") public Object lightweightAdvice(ProceedingJoinPoint pjp) throws Throwable { // minimal pre-processing Object result = pjp.proceed(); // minimal post-processing return result; }
@Around("execution(* com.example..*(..))") public Object heavyAdvice(ProceedingJoinPoint pjp) throws Throwable { // heavy processing before Thread.sleep(100); // simulate delay Object result = pjp.proceed(); // heavy processing after Thread.sleep(100); // simulate delay return result; }
| Pattern | Method Interception Overhead | Thread Blocking | Latency Impact | Verdict |
|---|---|---|---|---|
| Heavy processing in @Around advice | High (every method call) | Yes (Thread.sleep) | High latency per call | [X] Bad |
| Lightweight @Around advice | Low (minimal code) | No | Minimal latency | [OK] Good |
@Around advice in Spring AOP?@Around advice method?@Around advice code, what will be printed when someMethod() returns "Hello"?
@Around("execution(* someMethod())")
public Object aroundAdvice(ProceedingJoinPoint joinPoint) throws Throwable {
System.out.println("Before");
Object result = joinPoint.proceed();
System.out.println("After");
return result + " World";
}@Around advice method:
@Around("execution(* someMethod())")
public Object aroundAdvice(ProceedingJoinPoint joinPoint) {
System.out.println("Start");
Object result = joinPoint.proceed();
System.out.println("End");
return result;
}@Around advice that modifies the input argument of a method before execution and changes the returned result after execution. Which approach correctly achieves this?Pass the test and this pattern moves unknown