Challenge - 5 Problems
AOP Performance Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate2:00remaining
Output of a simple performance aspect
Given the following Spring Boot aspect code for measuring method execution time, what will be printed when the method
processData() is called?Spring Boot
import org.aspectj.lang.ProceedingJoinPoint; import org.aspectj.lang.annotation.Around; import org.aspectj.lang.annotation.Aspect; import org.springframework.stereotype.Component; @Aspect @Component public class PerformanceAspect { @Around("execution(* com.example.service.*.*(..))") public Object measureTime(ProceedingJoinPoint joinPoint) throws Throwable { long start = System.currentTimeMillis(); Object result = joinPoint.proceed(); long end = System.currentTimeMillis(); System.out.println(joinPoint.getSignature().getName() + " executed in " + (end - start) + "ms"); return result; } } // Assume processData() takes approximately 150ms to execute.
Attempts:
2 left
💡 Hint
Think about what the aspect measures and prints after the method finishes.
✗ Incorrect
The aspect measures the time before and after the method execution and prints the method name with the elapsed time in milliseconds. Since processData takes about 150ms, the output shows that time.
🧠 Conceptual
intermediate1:30remaining
Purpose of @Around advice in performance monitoring
What is the main reason to use
@Around advice in Spring AOP for performance monitoring?Attempts:
2 left
💡 Hint
Performance monitoring needs to know how long the method takes in total.
✗ Incorrect
The @Around advice wraps the method execution, allowing code to run before and after the method, which is essential to measure the total execution time.
❓ Troubleshoot
advanced2:30remaining
Why is the performance aspect not logging execution time?
A developer wrote this aspect to log execution time but sees no output in the console. What is the most likely cause?
Spring Boot
import org.aspectj.lang.ProceedingJoinPoint; import org.aspectj.lang.annotation.Around; import org.aspectj.lang.annotation.Aspect; import org.springframework.stereotype.Component; @Aspect @Component public class PerformanceAspect { @Around("execution(* com.example.service.*.*(..))") public Object measureTime(ProceedingJoinPoint joinPoint) throws Throwable { long start = System.currentTimeMillis(); Object result = joinPoint.proceed(); long end = System.currentTimeMillis(); System.out.println(joinPoint.getSignature().getName() + " executed in " + (end - start) + "ms"); return result; } }
Attempts:
2 left
💡 Hint
Check if the pointcut matches the actual method location.
✗ Incorrect
If the pointcut expression does not match any method, the advice never runs, so no output appears.
🔀 Workflow
advanced2:00remaining
Correct order of steps to add performance monitoring with AOP
Put these steps in the correct order to add performance monitoring using Spring AOP.
Attempts:
2 left
💡 Hint
Think about creating the aspect first, then defining what to monitor, then the advice, then testing.
✗ Incorrect
First create the aspect class, then define the pointcut, then write the advice, finally run and verify.
✅ Best Practice
expert3:00remaining
Best practice for logging performance in production
Which is the best practice for implementing performance monitoring with AOP in a production Spring Boot application?
Attempts:
2 left
💡 Hint
Think about flexible and configurable logging in production environments.
✗ Incorrect
Using a logging framework allows controlling log output via configuration without code changes, which is best for production.