Posts

Showing posts from 2019

Performance Monitoring of Java Classes with Spring AOP

Method performance monitoring is a trivial task and with Spring AOP it doesn't require any code change, just some simple configurations.  But unfortunately is not very useful on its own as it provide response time only and doesn't provide any other stats. One easy way to have some useful stats is to write a simple interceptor class instead of using Spring default one ( PerformanceMonitorInterceptor ).  Below is an example of this that provides periodic stats (last, average and greatest response time) as well as warning whenever a method response time exceeds a configured threshold. package com.myapp.web.interceptor; import java.util.concurrent.ConcurrentHashMap; import org.aopalliance.intercept.MethodInterceptor; import org.aopalliance.intercept.MethodInvocation; import org.slf4j.Logger; import org.slf4j.LoggerFactory; public class CustomPerformanceInterceptor implements MethodInterceptor {     Logger logger = LoggerFactory. getLogger (