Demo: building a mini @Timed with a proxy
On This Lesson 3 topics
This lesson is planned. The outline below lists the topics it will cover. The full lesson has not been published yet.
In this lesson
build an annotation-driven interceptor; prepares MID-009-LAB1.
Draft outline details
Step by step
- Define
@Timed(RUNTIME, METHOD) and an interfacePriceServicewith an implementation. - Write a
Proxy.newProxyInstancehandler that checks the annotation on the target method and logs elapsed time. - Call through the proxy; see the timing log.
- Planned mistake: annotate only the interface method and read the annotation from the implementation class (not found). Fix: look up the annotation on the target class method (and note Spring's own lookup rules).
- Add an internal call between two methods; show it is not timed (self-invocation).
- Discuss reflection cost and caching
Methodlookups.
Practice
Apply this lesson with the module's lab, exercises and quiz.
Marking a lesson complete is optional and you can undo it any time. Your progress stays in this browser.