0
0
Spring Bootframework~20 mins

AOP for performance monitoring in Spring Boot - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
AOP Performance Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate
2: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.
AprocessData executed in 150ms
BprocessData executed in 0ms
CprocessData executed in 150 seconds
DNo output printed
Attempts:
2 left
💡 Hint
Think about what the aspect measures and prints after the method finishes.
🧠 Conceptual
intermediate
1:30remaining
Purpose of @Around advice in performance monitoring
What is the main reason to use @Around advice in Spring AOP for performance monitoring?
ATo execute code before and after the target method to measure execution time
BTo only execute code before the target method starts
CTo replace the target method with a different implementation
DTo execute code only if the target method throws an exception
Attempts:
2 left
💡 Hint
Performance monitoring needs to know how long the method takes in total.
Troubleshoot
advanced
2: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;
    }
}
AThe method measureTime does not return the result
BThe target methods are not in package com.example.service
CThe @Aspect annotation is missing
DSystem.out.println does not print in Spring Boot
Attempts:
2 left
💡 Hint
Check if the pointcut matches the actual method location.
🔀 Workflow
advanced
2: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.
A1,3,2,4
B2,1,3,4
C1,2,3,4
D3,1,2,4
Attempts:
2 left
💡 Hint
Think about creating the aspect first, then defining what to monitor, then the advice, then testing.
Best Practice
expert
3: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?
AUse System.out.println in the aspect to log execution times
BThrow exceptions if method execution exceeds a threshold
CDisable the aspect in production to avoid overhead
DUse a logging framework like SLF4J with log levels to control output
Attempts:
2 left
💡 Hint
Think about flexible and configurable logging in production environments.