|
| |
"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: info@sys-con.com
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.
|