How can I measure the number of times and response time of a method called in a Spring Bean
I would like to measure the number of times a method is called on a service开发者_开发问答 provisioned by Spring.
In EJB land this information is usually provided by the container.
Now since spring is conceived when "Anything you can do, I can do better" was playing on the radio, I expect there to be a nice and elegant component hidden somewhere which I can weave into my application using a sprinkling of XML.
Does anybody know of such a component?
Have a look at JAMon API.
JAMon gathers aggregate performance statistics such as hits, execution times (total, average, minimum, maximum, standard deviation), as well as concurrency information such as simultaneous application requests. It is easy to use and provides multiple ways to view the reports.
Edit: Also as suggested by @duffymo , there are already available interceptors out of the box with spring for jamon integrarion. This link may provide a direction.
Yes, I'd look at the Spring interceptors and AOP for a "do better" solution. Maybe org.springframework.aop.interceptor.PerformanceMonitorInterceptor
will do what you want out of the box.
If none of the out of the box Interceptors meet your need, it's an easy matter to extend the interface, write your own to your exact requirements, and weave it in using Spring configuration.
You might also like to write your own method-level timing and logging. Here is an example I wrote that shows how to do it with Spring AOP.
精彩评论