Listing 1

1. public class BankAccount
2. {
3.    public void withdraw(double amount)
4.    {
5.       long startTime = System.currentTimeMillis();
6.       try
7.       {
8.          ...actual method body
9.       }
10.       finally
11.       {
12.          long endTime = System.currentTimeMillis() – startTime;
13.          System.out.println("withdraw took: " + endTime);
14.       }
15.    }
16. }

Listing 2

1. public class MetricsAspect implements some.aop.framework.Aspect
2. {
3.    public Object invoke(Invocation invocation) throws Throwable
4.    {
5.       long startTime = System.currentTimeMillis();
6.       try
7.       {
8.          return invocation.proceedWithMethod();
9.       }
10.       finally
11.       {
12.          long endTime = System.currentTimeMillis() – startTime;
13.          java.lang.reflect.Method m = invocation.getMethod();
14.          System.out.println("method " + m.toString() + " time: " + endTime + " ms");
15.       }
16.    }
17. }