0
0
Spring Bootframework~8 mins

@Around advice for full control in Spring Boot - Performance & Optimization

Choose your learning style9 modes available
Performance: @Around advice for full control
MEDIUM IMPACT
This affects the runtime execution speed and responsiveness of Spring Boot applications by intercepting method calls.
Controlling method execution with @Around advice
Spring Boot
@Around("execution(* com.example..*(..))")
public Object lightweightAdvice(ProceedingJoinPoint pjp) throws Throwable {
  // minimal pre-processing
  Object result = pjp.proceed();
  // minimal post-processing
  return result;
}
Minimal logic avoids blocking and keeps method interception fast, preserving app responsiveness.
📈 Performance GainReduces overhead to near zero, avoiding added latency per method call.
Controlling method execution with @Around advice
Spring Boot
@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;
}
Heavy processing or blocking calls inside @Around advice delay every intercepted method call, increasing response time.
📉 Performance CostAdds 200ms delay per method call intercepted, increasing latency and reducing throughput.
Performance Comparison
PatternMethod Interception OverheadThread BlockingLatency ImpactVerdict
Heavy processing in @Around adviceHigh (every method call)Yes (Thread.sleep)High latency per call[X] Bad
Lightweight @Around adviceLow (minimal code)NoMinimal latency[OK] Good
Rendering Pipeline
The @Around advice intercepts method calls before and after execution, adding extra steps in the call stack.
Method Invocation
Application Thread Execution
⚠️ BottleneckHeavy or blocking code inside advice increases method execution time and thread blocking.
Optimization Tips
1Avoid heavy or blocking code inside @Around advice to prevent slowing method calls.
2Use @Around advice sparingly and only on necessary methods to reduce overhead.
3Profile advice execution time with Java Flight Recorder to detect performance bottlenecks.
Performance Quiz - 3 Questions
Test your performance knowledge
What is the main performance risk of using heavy processing inside @Around advice?
AIt improves application startup time.
BIt reduces bundle size.
CIt increases method call latency and blocks threads.
DIt decreases memory usage.
DevTools: Spring Boot Actuator + Java Flight Recorder
How to check: Enable Actuator metrics and record method execution times with Java Flight Recorder to profile advice overhead.
What to look for: Look for increased method execution times and thread blocking during advice execution.