Archive for October, 2010

Recently I was in need to tune some of the java services which I had implemented for for an iPhone project. When integrating services with mobile and hand held devices, it is very important that the services respond in a matter of seconds. In order to tune the services and get the best UI experience, the obvious step is to find the slowest service. However the intriguing question was ….HOW?

Following are some of the alternates most developers do

  • Have a System.out / Log.debug after you enter and before you exit the service, which prints the time
  • Write and aspect using AOP and log the time before and after invocation of the method


Serious developers choose the second approach, since monitoring is a cross cutting concern.

Before you fire up you IDE and start writing an Aspect and all those AOP jargon, I would like to introduce you to a class from the Spring Framework core portfolio called “JamonPerformanceMonitorInterceptor”. As the name suggests, it is an AOP interceptor that hooks into the framework called JAMon. JAMon is a java monitoring framework and it sure is sweet.

To know more about JAMon check it out HERE. Make sure you download the jamon-2.7.jar file and put it on your classpath

That’s right, no writing of interceptors and joint points and what not AOP jargon out there.

All you need to to do is instantiate a JamonPerformanceMonitorInterceptor bean and tell it which all Spring beans to intercept

Add this to instantiate the bean

<bean id="jamonPerformanceMonitorInterceptor" class="org.springframework.aop.interceptor.JamonPerformanceMonitorInterceptor" >
   <property name="trackAllInvocations" value="true"></property>
   <property name="useDynamicLogger" value="true"></property>

Next create a “BeanNameAutoProxyCreator” and hook in the interceptor.

<bean id="autoProxyCreator" class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator">
	<property name="interceptorNames">
			<idref bean="jamonPerformanceMonitorInterceptor"/>
	<property name="beanNames">

All you need to do now is, tell the BeanNameAutoProxyCreator which all Spring beans to intercept.”paymentDao”,”paymentService” etc are all classic Spring beans. Voila, your services and dao are all being monitored.

Oh…And one last thing.

Make sure you set the log4 logging level to TRACE or else it will NOT work!!

In the follow article , I shall show you have to generate reports from the JAMON framework using a simple servlet.


Read Full Post »