快速业务通道

Classworking工具箱: 将aspect放到werk中 - 编程入门网

作者 佚名技术 来源 NET编程 浏览 发布时间 2012-06-14
oin);      System.out.print(''='');      System.out.print(result);      System.out.print(" took ");      System.out.print(time);      System.out.println(" ms.");    }    // return result from joinpoint execution    return result; }

Classworking工具箱: 将aspect放到werk中(8)

时间:2011-10-16 IBM Dennis Sosnoski

修改了 XML 配置文件以在 traceLong() 的地方使用 traceTimed() advice 方法后,用同样的参数值 “6” 运行它完全不显示任何踪迹信息,因为整个执行用时小于最小时间。如果使用值“15”,那么就得 到清单 9 所示的输出。

清单 9. 带时间筛选器的输出

Entering fibo(15)   Entering fibo(14)   Entering fibo(13)    Entering fibo(12)    Leaving fibo(11)=89 took 2 ms.    Leaving fibo(10)=55 took 2 ms.    Leaving fibo(12)=144 took 11 ms.    Entering fibo(11)    Leaving fibo(10)=55 took 2 ms.    Leaving fibo(9)=34 took 2 ms.    Leaving fibo(11)=89 took 5 ms.   Leaving fibo(13)=233 took 19 ms.   Entering fibo(12)    Leaving fibo(11)=89 took 2 ms.    Entering fibo(10)    Entering fibo(8)     Entering fibo(6)     Leaving fibo(4)=3 took 2 ms.     Leaving fibo(6)=8 took 4 ms.    Leaving fibo(8)=21 took 6 ms.    Leaving fibo(10)=55 took 6 ms.   Leaving fibo(12)=144 took 10 ms.   Leaving fibo(14)=377 took 29 ms.   Entering fibo(13)   Entering fibo(12)    Leaving fibo(11)=89 took 2 ms.    Leaving fibo(10)=55 took 2 ms.   Leaving fibo(12)=144 took 6 ms.   Entering fibo(11)    Leaving fibo(10)=55 took 2 ms.   Leaving fibo(11)=89 took 3 ms.   Leaving fibo(13)=233 took 9 ms. Leaving fibo(15)=610 took 95 ms. Fibo[15] is 610

清单 9 输出正是我想要看到的,因此现在可以抛开斐波纳契,转向真正的应用程序了。我将在下个月 的专栏中做这件事。

结束语

在本次专栏中,介绍了如何用 AspectWerkz 实现带性能度量增强的基本执行跟踪。下个月的专栏进一 步拓展这一概念,扩展跟踪 aspect 并将它应用到复杂的带有自己的内置日志记录的真实世界框架上,以 发现 aspect 方法在哪些地方可以很好地发挥作用 —— 在哪些地方不能。aspect 是否可以使我们免于 日志记录代码的烦扰?请继续关注并找出答案。

本文配套源码

凌众科技专业提供服务器租用、服务器托管、企业邮局、虚拟主机等服务,公司网站:http://www.lingzhong.cn 为了给广大客户了解更多的技术信息,本技术文章收集来源于网络,凌众科技尊重文章作者的版权,如果有涉及你的版权有必要删除你的文章,请和我们联系。以上信息与文章正文是不可分割的一部分,如果您要转载本文章,请保留以上信息,谢谢!

分享到: 更多

Copyright ©1999-2011 厦门凌众科技有限公司 厦门优通互联科技开发有限公司 All rights reserved

地址(ADD):厦门软件园二期望海路63号701E(东南融通旁) 邮编(ZIP):361008

电话:0592-5908028 传真:0592-5908039 咨询信箱:web@lingzhong.cn 咨询OICQ:173723134

《中华人民共和国增值电信业务经营许可证》闽B2-20100024  ICP备案:闽ICP备05037997号