HomeDigital EditionSys-Con RadioSearch Java Cd
Advanced Java AWT Book Reviews/Excerpts Client Server Corba Editorials Embedded Java Enterprise Java IDE's Industry Watch Integration Interviews Java Applet Java & Databases Java & Web Services Java Fundamentals Java Native Interface Java Servlets Java Beans J2ME Libraries .NET Object Orientation Observations/IMHO Product Reviews Scalability & Performance Security Server Side Source Code Straight Talking Swing Threads Using Java with others Wireless XML
 

"It's the Aspects"
Vol. 8, Issue 12, p. 12

	



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. }

 

All Rights Reserved
Copyright ©  2004 SYS-CON Media, Inc.
  E-mail: [email protected]

Java and Java-based marks are trademarks or registered trademarks of Sun Microsystems, Inc. in the United States and other countries. SYS-CON Publications, Inc. is independent of Sun Microsystems, Inc.