A strategy that works to me in java ee was:
Create a class with a method annotated with @AroundInvoke
;
@Singleton
public class TimedInterceptor implements Serializable {
@AroundInvoke
public Object logMethod(InvocationContext ic) throws Exception {
Date start = new Date();
Object result = ic.proceed();
Date end = new Date();
System.out.println("time: " + (end.getTime - start.getTime()));
return result;
}
}
Annotate the method that you want to monitoring:
@Interceptors(TimedInterceptor.class)
public void onMessage(final Message message) { ...
I hope this can help.